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
posted
0
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
posted
0
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
posted
0
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
posted
0
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