JSP JavaBeans problem in scope="session" attribute

J

jrefactors

I use scope="session" in <jsp:useBean id="user"
class="com.proj1.model.User" scope="session"/>,
and I expect the bean name user doesn't need to redeclare in other
pages,
because the bean is available throughout the session.

User Id = 1234 is shown in test1.jsp, but when the user click the
submit button, then it has error

Parsing of JSP File '/test/test2.jsp' failed:
/test/test2.jsp(1): "user" is not a defined bean variable on this page
probably occurred due to an error in /test/test2.jsp line 1:
<H1>User ID = <jsp:getProperty name="user" property="userId"/></H1>

test1.jsp
=========
<jsp:useBean id="user" class="com.proj1.model.User" scope="session"/>
<jsp:setProperty name="user" property="userId" value="1234"/>
<H1>User ID = <jsp:getProperty name="user" property="userId"/></H1>
<html>
<head>
</head>
<body>
<form action="test2.jsp" method="POST">
<input type="submit" value="submit here">
</form>
</body>
</html>

test2.jsp
=========
<H1>User ID = <jsp:getProperty name="user" property="userId"/></H1>
any ideas? please advise.

thanks!!
 
R

Robert kebernet Cooper

pages,
because the bean is available throughout the session.


You still need to have the bean tag in your other pages though. The
"session" means that a new bean won't be created on another page,
rather the bean you created on the first page will be maintained.
 
J

jrefactors

You still need to have the bean tag in your other pages though. The
"session" means that a new bean won't be created on another page,
rather the bean you created on the first page will be maintained.

What do you mean by need the bean tag?

Do I need to declare the following in page2.jsp also?
<jsp:useBean id="user" class="com.proj1.model.User" scope="session"/>
 
J

jrefactors

You still need to have the bean tag in your other pages though. The
"session" means that a new bean won't be created on another page,
rather the bean you created on the first page will be maintained.
what do you mean by bean tag? <jsp:useBean id="user"> ??
 
J

John C. Bollinger

What do you mean by need the bean tag?

Do I need to declare the following in page2.jsp also?
<jsp:useBean id="user" class="com.proj1.model.User" scope="session"/>

Yes, exactly so. The main purpose of a <jsp:useBean> action is to
_declare_ a bean to the rest of the page implementation, and every page
must declare all the beans it uses. The action will create a bean of
the specified type, bound to the specified name, and assigned to the
appropriate scope if none yet exists, but that is best considered a side
effect rather than the goal of the action.


John Bollinger
(e-mail address removed)
 
J

J2EEStar

Hi,

Try this below steps........

first try to forward the Request/Response Object from test1.jsp page to
test2.jsp page. then try to get property as u did.

J2EEStar.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top