wood burning stoves
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
JavaRanch » Java Forums » Java » JSP
Bookmark "Bean and JSP" Watch "Bean and JSP" New topic

Bean and JSP

Sarthishari Kumar

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
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63841

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).

[Asking smart questions] [About Bear] [Books by Bear]
Sarthishari Kumar

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??
arul murug

Joined: Aug 08, 2002
Posts: 24
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 .

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