Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Using Session Bean Info in a server

 
Goldie Hawn
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I want to use some of the bean properties I set thru a jsp page in a servlet. Can someone guide how do i do that....
Thanks
 
Sowmya Vinay
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Goldie Hawn:
Hi,
I want to use some of the bean properties I set thru a jsp page in a servlet. Can someone guide how do i do that....
Thanks

If the bean which you have used in the jsp page has its scope set as "session", then in the servlet, extract the same from the session by a session.getValue() or session.getAttribute() whichever holds good. Please note that the bean is created(first time it is accessed in the jsp) and stored in the session with its name being the name attribute you set in the "jsp:usebean" tag.
Lets say that you are using a bean named "Book" and set the name attribute of usebean tag as "book1".
i.e
<jsp:usebean name="book1" class="Book.class" scope="session">
then within the session, this bean is stored with name as "book1". So in order to extract it from session,
Book otherbook = (Book)session.getValue("book1");
Now, you get the bean object from session and can access its properties .
I hope I have answered your question!
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Goldie Hawn:
I want to use some of the bean properties I set thru a jsp page in a servlet. Can someone guide how do i do that....

Assuming your beans have session scoped, they are accessible as attributes in the HttpSession object. I.e.
MyBean myBean = (MyBean)request.getSession().getAttribute("myBean");
out.println(myBean.getHelloWorld());
- Peter
 
james_deshpande
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI BHIDU(FRIEND),
I HAVE BEANS IN A FOLDER OF TOMCAT/WEBAPPS.
WHEN I TRY TO ACCESS BEAN IN JSP I GET ERROR THAT BEAN NOT FOUND.
DO I NEED TO SET CLASS PATH OF BEAN??
PLZ LEMME KNOW EXACT STEPS OF USING BEAN:
WHERE TO STORE THEN WHAT??
THEN JSP:USEBEAN ETC.
 
Vedprakash Pathak
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi James,
Yes you do need to set the classpath for the beans or store them in one of the sub directories in the classpath and give the path in the class property of the jsp:usebean. Hope this helps u
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic