Rookie question about Sessions
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Geoff_Peters
Posted On:   Monday, March 18, 2002 08:50 AM

Yes this is a rookie question, sorry to bother you...

I have successfully configured Tomcat 4.0 JDBCRealm with an Access97 database, can login based on roles, etc no troubles. The rest of my app (SQL statements) use the UserId in the where clause, so how do I pass the logged in userId to some sort of session variable that I can retrieve at any point in the application (all servlets)? I am assuming this is set somewhere in the server.xml or web.xml file, no idea how to do it. Thanks in advance! Geoff

Re: Rookie question about Sessions

Posted By:   Ed_Hoden  
Posted On:   Monday, March 18, 2002 02:01 PM

If you are doing your work from servlets you will probably use the following lines to set and get session variables:

request.getSession().putValue( "some.id.here", userId );

userId = (String) request.getSession().getValue( "some.id.here" );


where request is the servlet's HttpServletRequest.


If you are using JSP's, you can refer directly to the session with the "session" property inherent to JSP's.

session.putValue( "some.id.here", userId );


For more information, check out the javadoc pages on HttpSession. -HTH Ed
About | Sitemap | Contact