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.
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 .
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