At what scoping level should the decleration of an HttpSession be at? Is it okay be at the field level or should it be declared in either doGet() or doPost and passed along to methods needing access? Thanks, Kenny
Asher Tarnopolski
Ranch Hand
Joined: Jul 28, 2001
Posts: 260
posted
0
you get your session by calling getSesison() on your HttpServletRequest object which is available in all doXxx() methods...
Asher Tarnopolski
SCJP,SCWCD
Marty Hall
Author
Ranch Hand
Joined: Jan 02, 2003
Posts: 111
posted
0
At what scoping level should the decleration of an HttpSession be at? Is it okay be at the field level or should it be declared in either doGet() or doPost and passed along to methods needing access?
It makes no sense to assign session objects to servlet fields (instance variables). Fields are shared by all users who access the servlet, whereas sessions are specific to a user. So, assign session objects to local variables only (reassign it on the next request -- the point is that request.getSession(true) returns the same object next time if it is the same client). Or am I misunderstanding your question? Cheers- - Marty
Java training and consulting<br /><a href="http://www.coreservlets.com/" target="_blank" rel="nofollow">http://www.coreservlets.com/</a>