• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using Session Bean Info in a server

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic