aspose file tools*
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
Author

Instantiate a bean in a servlet

Sharmila Abkari
Greenhorn

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.
Thanks
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
Sharmila,
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
sb.setData("somearg");
4. pass this bean to jsp
HttpSession httpSession = request.getSession(false);
httpSession.setAttribute("myBean",mb);
getServletContext().getRequestDispatcher(response.encodeURL("/login/welcome.jsp"));

regds
maha anna

[This message has been edited by maha anna (edited March 30, 2001).]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Instantiate a bean in a servlet