Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How come I can pull a session attribute in a JSP page but not in a Servlet?

 
John Piper
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a web application that begins with a login page. During the verification of that login a session is created and the ID used to login is saved as an attribute. That ID is then suppose to be displayed in the pages that user navigates to. So far I can only get it to display in a JSP page but everything I try in a Servlet page does not work.

Here is the logic I used in my login verification page:



Here is the Bean I created UserBean2:



The part that works is when I try to call the ID in a jsp page. I do that with this:



But to call it in a Servlet page I've tried everything under the sun and nothing has worked correctly.

I even tried a getAttributeNames thinking that would give me the info I needed but all I received was this: (bokay is the ID that was used to login to this particular session)

bokay: bokay
userBean2: HWpackage.UserBean2@257ccb2f


Any ideas as to what I'm suppose to use in the JSP page to display the ID, which in this case happens to be "bokay"?

Thanks everyone!
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65338
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
userBean2: HWpackage.UserBean2@257ccb2f


OK, so it appears that the scoped variable userBean2 exists in the session. So what's the problem?
 
John Piper
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
userBean2: HWpackage.UserBean2@257ccb2f


OK, so it appears that the scoped variable userBean2 exists in the session. So what's the problem?


I can't figure out the correct code to use in the Servlet that will display the ID like I am able to do in the JSP page by using ${userBean2.username}.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65338
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's just Java. Call the getter.
 
Jessid Leon Velez Gutierrez
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this Bean is missing the no arg constructor, i think...


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic