IntelliJ Java IDE
The moose likes Servlets and the fly likes Using Session Bean Info in a server Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "Using Session Bean Info in a server" Watch "Using Session Bean Info in a server" New topic
Author

Using Session Bean Info in a server

Goldie Hawn
Greenhorn

Joined: Mar 02, 2001
Posts: 2
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

Joined: Feb 01, 2001
Posts: 24
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

Joined: Apr 20, 2000
Posts: 3252
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

Joined: Feb 13, 2001
Posts: 23
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

Joined: Mar 06, 2001
Posts: 24
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
 
 
subject: Using Session Bean Info in a server
 
Threads others viewed
looking for Java bean book
how to access same javabean in previous web page?
looking for Java bean book
Usage of EJB - Need clarification
Passing a Parameter via Ajax
MyEclipse, The Clear Choice

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture