• 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:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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).]
 
Liar, liar, pants on fire! refreshing plug:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic