Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Calling JavaBean From JSP

843836Apr 30 2004 — edited May 4 2004
I wrote a very simple program to try to figure out how to use a javabean from multiple jsp pages. There are 2 jsps ("page1.jsp", "page2.jsp") and 1 bean ("TestBean.java"). The 1st JSP uses a bean called "myBean". It sets a value and successfully displays the value using the bean id ("myBean"). When I click the link to go to page2.jsp, however, I get a "cannot resolve symbol" error (italicized below). This error doesn't make sense to me because I set the bean to "session" scope and I never closed my browser during the session. I know I must be missing something very basic but I can't figure out what it is. Any help would be much appreciated!


C:\jakarta-tomcat-5.0.18\work\Catalina\localhost\test\org\apache\jsp\page2_jsp.java:46: cannot resolve symbol
symbol : variable myBean
location: class org.apache.jsp.page2_jsp
int beanInt = myBean.getMyInt();
^
1 error

-----------------------------------------------------------
Page1.jsp:
<jsp:useBean id="myBean" scope="session" class="test.TestBean" />
<jsp:setProperty name="myBean" property="myInt" value="99" />
<html><head> <title></title></head><body>

<% int someInt = myBean.getMyInt(); %>

<%= "someInt = " + someInt %>

<A href="page2.jsp">Continue</A>

</body></html>
-----------------------------------------------------------
Page2.jsp:
<html>
<head><title></title></head><body>

<%
     int beanInt = myBean.getMyInt();
%>

<%= "beanInt = " + beanInt %>

</body></html>
-----------------------------------------------------------
TestBean.java:
package test;
public class TestBean {
	int myInt;

	public void setMyInt(int a) {
		myInt = a;
	}

	public int getMyInt() {
		return myInt;
	}
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 1 2004
Added on Apr 30 2004
6 comments
123 views