This week's book giveaway is in the Android forum.
We're giving away four copies of Head First Android and have Dawn & David Griffiths on-line!
See this thread for details.
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 Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Automatic Session Expiry" Watch "Automatic Session Expiry" New topic

Automatic Session Expiry

sabeerdeenk kaderhussaindeen

Joined: Oct 29, 2010
Posts: 3
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?

userId Text box
submit button

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

RequestDispatcher rd = request.getRequestDispatcher("Welcome.jsp");
} rd.forward(request, response);

Paul Sturrock

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

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

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

Joined: Jun 06, 2008
Posts: 5

Hi sabeerdeenk kaderhussaindeen

To peform this operation programiticaly , we may also use the autorefresh feature of servlet
Consider Paul's rocket mass heater.
subject: Automatic Session Expiry
It's not a secret anymore!