• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JavaBeans and Servlets

 
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've created a JavaBean called StudentBean. I have a form in index.jsp which dispatches control to the LoginAction servlet. In that servlet, I import my JavaBean and create a new instance of it. Then I call the set methods of the Bean and set the login name. Once that is done, I use the redirect method to send control to another page. Then I use the jsp:useBean attribute in the jsp to make a reference to my StudentBean. Later in the html, I use the jsp:getProperty attribute to get the value of the login name from above. It comes back as null for some reason.
I'm thinking I should make an entry in my web.xml to inform my application that the StudentBean is available for use, etc. Can anybody help me out?
 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
That all depends on what is the scope of the bean that you are creating. There are three scopes:
1) request
2) session
3) application
The scope defines the life time of the bean. The scenario you are defining needs a session bean.
The bean name should be same/identical in all the pages that uses that bean and the scope should be set to session.
Check it and then inform accordingly.
Thanks
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would not recommend using the session for this purpose. The most common means of acheiving what you are after is to place the bean as an attribute on the request, and to then forward (rather than redirect) to the JSP.
hth,
bear
 
reply
    Bookmark Topic Watch Topic
  • New Topic