*
The moose likes JSP and the fly likes use bean instance in servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "use bean instance in servlet" Watch "use bean instance in servlet" New topic
Author

use bean instance in servlet

Rajah Nagur
Ranch Hand

Joined: Nov 06, 2002
Posts: 239
Hello all,
How to get the bean instance of JSP in servlet?
I have a x.jsp, there are 3 input fields.
I have a xbean.java for the above input form of the x.jsp.
jsp use bean tag is used in this x.jsp. set property * is used to populate all the fields that the user has entered in this input form in the bean(which the jsp engine does).
How to get this xbean instance in the servlet for processing? so that i can call get methods of this xbean to get the user input and process.
Thanks in advance


You can't wake a person who is <b><i>pretending</i></b> to be asleep.<br />Like what <b>"it"</b> does not like - <i> Gurdjieff </i>
Bhushan Jawle
Ranch Hand

Joined: Nov 22, 2001
Posts: 249
Hi,
Depending on context of the bean, just retrieve attribute with name same as bean id used in JSP and cast it to the bean class and you are ready to use it.
Bhushan
Rajah Nagur
Ranch Hand

Joined: Nov 06, 2002
Posts: 239
bean Context...i did not understand.
what is the exact code..??
is it avilable in request object?
Devesh H Rao
Ranch Hand

Joined: Feb 09, 2002
Posts: 687

The scope of the bean u have declared in the jsp decides how u can fetch it in the servlet.
if the scope is request and the id of bean is "xBean" u can retrive it using
(TypeCast)request.getAttribute("xBean");
or if the scope of bean is session in jsp the same can be retrived from
(TypeCast)session.getAttribute("xBean");
Devesh
 
Don't get me started about those stupid light bulbs.
 
subject: use bean instance in servlet