This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Instantiate a bean in a servlet

 
Sharmila Abkari
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1467
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic