aspose file tools
The moose likes Servlets and the fly likes Question on HttpSession Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "Question on HttpSession" Watch "Question on HttpSession" New topic
Author

Question on HttpSession

mallikarjun dontamsetti
Ranch Hand

Joined: Mar 18, 2011
Posts: 233

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

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Jan 10, 2002
Posts: 56204
    
  13

You should not be using session scope to send data to the JSP in the same request -- use request scope.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35252
    
    7
Actually, getSession does both - creating and getting a session, depending on the circumstances. Its javadocs explain that.


Android appsImageJ pluginsJava web charts
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Mar 18, 2011
Posts: 233

Then am i doing correct job. or is there any alternative for this.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Question on HttpSession
 
Similar Threads
session.isNew() gives true after request.getSession(false)
exception
Problem with session tracking
servlet cant see getServletContext() from inheritance
HttpSessionListener