• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HttpSession declaration scope

 
Kenny Dilger
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 260
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you get your session by calling getSesison() on your HttpServletRequest object which is available in all doXxx() methods...
 
Marty Hall
Author
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic