Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JavaBeans and Servlets  RSS feed

 
Chris Stewart
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
  • 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?
 
Murtaza Hussaini
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!