This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
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

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
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
jQuery in Action, 3rd edition