Hi, Amudha ! Try on request.getsession(true); It's will create a session object on the first time and return the session object if it already exists. Regards, Paulo Lima.
Originally posted by Amudha Loganathan: Hi, To keep the current session alive which one of the below is the best practise? 1. using request.getsession() 2. using request.getsession(false) Can any one help me to solve this TAI, AM
paulocdl The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at JavaRanch's naming policy. . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please change to a new name which meets the requirements. Thanks.
I think most everyone has covered the fact that the various getSession() methods simply return a session if it exists OR create a session if there isn't one ( getSession(true) ) do not create a new session if one doesn't already exist ( getSession(false) ) If you are trying to keep the session alive between delayed requests you should be able to set the session timeout period somwhere in the servers configuration. Tomcat allows you to never timeout by setting the timeout period to -1.
Call setMaxInactiveInterval(int interval)on HttpSession. "Specifies the time, in seconds, between client requests before the servlet container will invalidate this session. A negative time indicates the session should never timeout". You can also specify time out in the Descriptor. Thanks Sanjay
Many servlet programming problems can be due to not realizing the getSession( true ) has created a new session instead of recovering one. You can use the HttpSession method: boolean isNew() to detect when this happens. Bill