Simple way to implement Session Timeout in J2EE application or in Portal

This Article shows how easy we can implement the session timeout in J2EE applications using the HTML meta tags

You can place the same code in Theme default.JSP if you want implement session timeout using this approach in WebSphere Portal Applicaitons


Session_Expiry_Test.JSP

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<meta http-equiv="refresh" content="<%= session.getMaxInactiveInterval() %>;url=dummy_login.jsp">
</head>
<body>

<h1>Welcome, dude with a session!</h1>
Your session will expire in <%= session.getMaxInactiveInterval() %> seconds at which time your browser will be redirected to the login page and any and all unsaved changes will be lost.
<br>
Thank you for your cooperation!
</body>
</html>


dumy_login.jsp
<%@page contentType="text/html"%><%@page pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"   "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>JSP Page</title>
</head>
<body>
<h1>You have reached this page because your session has timed out.</h1>
</body>
</html>

3 comments:

  1. getting error on session as "session cannot be resolved" , could you please help to resolve this , do we need any page import ? I'm trying form theme

    ReplyDelete
    Replies
    1. "session" is predefined variable in the JSP and it must be available by default in JSP.

      Delete
  2. This comment has been removed by a blog administrator.

    ReplyDelete