my dog learned polymorphism
The moose likes Servlets and the fly likes Instantiate a bean in a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Instantiate a bean in a servlet" Watch "Instantiate a bean in a servlet" New topic

Instantiate a bean in a servlet

Sharmila Abkari

Joined: Mar 29, 2001
Posts: 15
what i am required to do is, according to some condition instantiate 3 different bean in the servlet.
The buisness logic is in the bean, and then i also need to know how to pass the data in the bean to the JSP's.
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
Here is a sample code. Assume "SampleBean" is your bean's name.
1.In your servlet code "import SampleBean;"
2.Make an instance
SampleBean sb = new SampleBean();
or any other bean's constructor you would like to call
3. Call the needed methods on this bean instance
4. pass this bean to jsp
HttpSession httpSession = request.getSession(false);

maha anna

[This message has been edited by maha anna (edited March 30, 2001).]
I agree. Here's the link:
subject: Instantiate a bean in a servlet
It's not a secret anymore!