aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes jsp:useBean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "jsp:useBean" Watch "jsp:useBean" New topic
Author

jsp:useBean

Ramya Iyer
Ranch Hand

Joined: Jul 29, 2003
Posts: 66
Hi,

Can someone help me in understanding the scope attribute of jsp:useBean tag. If I set the scope to session, would the bean property be accesible using jsp:getProperty tag from any jsp file? Also shd I have the jsp:useBean re-declared in the pages that I would be accesing the property? This is my understanding, but when I tried out with a code, I get the value as null.

Code where I am setting the bean values.


Code 1 - where I access it. It works fine here.



Code 2 - Here I am trying to acess the session bean and it does not work.
I get the value as null


Pls help.

Thanks and Regards,
Ramya.
Scott Johnson
Ranch Hand

Joined: Aug 24, 2005
Posts: 518
In your servlet, you are storing the Person in the Request object not the Session object:



Also, in your first JSP, you are creating a bean, storing it in the session and populating it from Person in the request object. So, yes, you will see the value when you call getProperty.

In your second JSP, you are creating a bean, storing it in the session but never populating it. (There is no setProperty tag.) So, no, you will not see the value when you call getProperty.

The above assumes that you start a new session then call the servlet which forwards to one of the JSPs. (The useBean tag will check the Session for an existing Person and use that if it exists, but it won't in a new session.)

Suppose you change the scenario such that the servlet executes and forwards to JSP 1 and then you call JSP 2 in the same session. In this case, you would see the name displayed in JSP 2 because JSP1 would have stored a populated Person object in the Session.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jsp:useBean