aspose file tools*
The moose likes Servlets and the fly likes servlet to bean to jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlet to bean to jsp" Watch "servlet to bean to jsp" New topic
Author

servlet to bean to jsp

Shrikanth Goloposwami
Greenhorn

Joined: Feb 09, 2001
Posts: 7
Hi guys & gals,
I am trying to access a bean which is set from a servlet in a jsp. Is this only accomplished by placing the bean in the session? If this is the case, can servlets and jsps share sessions with one another? If this isn't the case, how do servlets and jsp share objects?
Sam Dalton
Author
Ranch Hand

Joined: Jul 26, 2001
Posts: 170
If you put a bean in the session in a servlet, you will indeed be able to access it in the session from a JSP (they are the SAME session) use request.getSession().getAttribute(attName)
You could also place the bean in the request (request.setAttribute) but be aware that that bean will only be avaliable in a JSP that is part of the same request....
Other options are to place the bean in the servletcontext (if you want it to be accessable by all JSPs and servlets in your webapp..)

S
Originally posted by Shrikanth Goloposwami:
Hi guys & gals,
I am trying to access a bean which is set from a servlet in a jsp. Is this only accomplished by placing the bean in the session? If this is the case, can servlets and jsps share sessions with one another? If this isn't the case, how do servlets and jsp share objects?


<a href="http://www.samjdalton.com" target="_blank" rel="nofollow">Sam Dalton</a>,<br />Co-author of [http://www.amazon.com/exec/obidos/tg/detail/-/1590592255/qid=1068633302//ref=sr_8_xs_ap_i0_xgl14/104-4904002-9274339?v=glance&s=books&n=507846]Professional JSP 2.0[/URL] (October 2003)<br />Co-author of <a href="http://www.amazon.com/exec/obidos/ASIN/1861007701/ref=ase_electricporkchop" target="_blank" rel="nofollow">Professional SCWCD Certification</a><br />Co-author of <a href="http://www.amazon.com/exec/obidos/ASIN/186100561X/ref=ase_electricporkchop" target="_blank" rel="nofollow">Professional Java Servlets 2.3</a>
Shrikanth Goloposwami
Greenhorn

Joined: Feb 09, 2001
Posts: 7
So if I do:
request.setAttribute("BeanName", _beanName);
getServletConfig().getServletContext().getRequestDispatcher("/jsp/bean.jsp").forward(request,response);
then I can access this bean in bean.jsp by:
<jsp:useBean id="BeanName" scope="request" class="com.domain.BeanName">
</jsp:useBean>
Is this correct? I am not successful using the above scenerio.
 
wood burning stoves
 
subject: servlet to bean to jsp