• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Question on HttpSession

 
Ranch Hand
Posts: 246
Firefox Browser Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.



 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 .
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Then am i doing correct job. or is there any alternative for this.
 
reply
    Bookmark Topic Watch Topic
  • New Topic