• Post Reply Bookmark Topic Watch Topic
  • New Topic

Question on HttpSession  RSS feed

 
mallikarjun dontamsetti
Ranch Hand
Posts: 246
Firefox Browser Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have n number of servlets with doProcess() methode and am creating session in each servlet for setting various variable values from login bean to data needed for jsp from DB. my doubt is am i need to create session object in each servlet, logged a user. or is there any alternative way to do this.



 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you are not creating session in every servlets. actually you are getting session which is created by container from request.

you (get)create session for a user upon successful login then, put user specific detail such as role (authorization info ...) into session only once in LoginServlet or something like that. session is available to all n numbers of servlets until it get invalidate .
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66156
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should not be using session scope to send data to the JSP in the same request -- use request scope.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, getSession does both - creating and getting a session, depending on the circumstances. Its javadocs explain that.
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry..Sorry...
Ulf Dittmer wrote:Actually, getSession does both - creating and getting a session, depending on the circumstances. Its javadocs explain that.

Exactly

getSession(boolean create)
Returns the current HttpSession associated with this request or, if there is no current session and create is true, returns a new session.


in case of JSP request container creates one implicitly

 
mallikarjun dontamsetti
Ranch Hand
Posts: 246
Firefox Browser Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then am i doing correct job. or is there any alternative for this.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!