wood burning stoves 2.0*
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 Android Security Essentials Live Lessons this week in the Android 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
 
Don't get me started about those stupid light bulbs.
 
subject: Automatic Session Expiry
 
Similar Threads
Session timeout in struts
Doubt in Session Time out.
what is session expunging?was asked this question in an interview?
Setting session timeout dynamically in Java code
Error: Requested resourse() not available