• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to use a Session Variable in JSP

 
Joey Alencar
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd like to know how can I implement and use a Session Variable in JSP, because I'd like to save the userid on logon.
Thanks.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JSP pages automatically have a HttpSession variable named session unless you put session="false" in the <%@ page tag
See section 2.8 in the JSP 1.1 API documentation for all of the "implicit objects" on a page.
See the Java servlet docs on how to attach objects to a session.
Bill

------------------
author of:
 
Jayson Falkner
Author
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
'Session variable' is a little loosely defined. To make an object stay alive for the entire session check out this FAQ.
Or alternatively you may stash information such as a username in a cookie, similar to how JSP already does session tracking. Here is a FAQ for using cookies.
 
Joey Alencar
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jayson Falkner, this is what I was looking for.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!