• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Instantiate a bean in a servlet

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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).]
 
reply
    Bookmark Topic Watch Topic
  • New Topic