my dog learned polymorphism*
The moose likes JSP and the fly likes Bean and JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Bean and JSP" Watch "Bean and JSP" New topic
Author

Bean and JSP

Sarthishari Kumar
Greenhorn

Joined: Apr 21, 2003
Posts: 19
Am just trying to do this. Help me.
Am setting a Bean Property in a Servlet.
After that i am transferring the control to a JSP page.
i want to retrieve that property in the JSP page.
Don't want to set that Bean as a Session Object and retrieve it in the JSP page.
Can it be done??
Waiting for all ur replies
Sathish
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61103
    
  66

The most comment method of passing beans, or any other Java data, from a servlet to a JSP (assuming that you are forwarding) is to tack it onto the request via request.setAttribute().
You can then retrieve the bean in the JSP either via the request.getAttribute() method, or with the JSP useBean tag.
Your instinct to not just throw transient data onto the session is a good one. The session should be reserved for holding data that truly needs to be held for the duration of the session (login authentication is a good example).
hth,
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sarthishari Kumar
Greenhorn

Joined: Apr 21, 2003
Posts: 19
Hi Bear
thanx for ur reply.
Can it be done in any other way??
Other than Session objects and Request Attributes can this be done??
Just curious??
Sathish
arul murug
Greenhorn

Joined: Aug 08, 2002
Posts: 24
Hi
You can store your bean in Pagecontext or some other user managed(container) object but still you need to add and pass the reference in any one of these three objects request or session or servletcontext .
Arul


SCJP2<br />SCWCD<br />UML & OOAD - IBM 486
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Bean and JSP