• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

per-session instance of servlet?

 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I read in another post by William Brogden that there's only one instance of a servlet, not one per user session like with beans. Maybe I read that wrong, but if that's true, how do I access user info from that servlet?
For example, I've got a form that submits to a JSP, and the JSP can use the usebean tag and pull info from the user's account info bean to find out what info the user has access to. I'm trying to convert that form to post to a servlet instead, but in that servlet, I no longer have access to the user's account info bean, and I wouldn't want to just trust the request parameters, because someone may be trying to fool the system into giving them someone else's information...
 
Ray Stojonic
Ranch Hand
Posts: 326
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given:
A servlet may have many sessions, a session may have many requests
and
a user may have one session ( okay, they may be using multiple browsers and have multiple sessions, but only if you let them log in more than once)
then
if you store the userbean in the session, you'll have access to it from your servlet for the life of the session.
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, how do you access those beans from servlets? Is there something like a JSP's usebean tag for servlets?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13073
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not look at the JavaDocs for HttpSession in the javax.servlet.http package? Or maybe buy a good book on servlets or find a tutorial. Hint - the javabean object will be in the session under the name used in the JSP. Take a look at the servlet code produced by the JSP compiler to see where it happens.
It really doesn't make any sense to try to pick up your knowledge of servlets one question at a time when all these great resources exist.
Bill
[ February 18, 2004: Message edited by: William Brogden ]
 
Stephen Huey
Ranch Hand
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agreed!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic