File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Automatic Session Expiry Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Automatic Session Expiry" Watch "Automatic Session Expiry" New topic
Author

Automatic Session Expiry

sabeerdeenk kaderhussaindeen
Greenhorn

Joined: Oct 29, 2010
Posts: 3
Hi..
login.jsp --> MyServlet --> WelcomePage.jsp

i want to make the session time out when i keep WelcomePage.jsp for more than 2 minutes,
and control has to come to login.jsp what code i have to write in welcome.jsp to achieve this?

login.jsp
=========
userId Text box
submit button


MyServlet
=========
String loginId = request.getParameter("userId");
HttpSession session = null;
session = request.getSession(true);
session.setAttribute("LoginId", loginId);

if(loginId.equals("abc"){
RequestDispatcher rd = request.getRequestDispatcher("Welcome.jsp");
} rd.forward(request, response);

web.xml
=======
<session-config>
<session-timeout>2</session-timeout>
</session-config>
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Have you considered using standard container managed security? It will give you the behaviour you want without needing to code it yourself.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
sabeerdeenk kaderhussaindeen
Greenhorn

Joined: Oct 29, 2010
Posts: 3
thanks for your reply... as a beginner i want to achieve this through code.. please help me!!
sabeerdeenk kaderhussaindeen
Greenhorn

Joined: Oct 29, 2010
Posts: 3
i my self tried and got it!
sheetanshu krishna
Greenhorn

Joined: Jun 06, 2008
Posts: 5

Hi sabeerdeenk kaderhussaindeen

To peform this operation programiticaly , we may also use the autorefresh feature of servlet
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Automatic Session Expiry