Hi Friends,
I have developed simple web-application which contains session timeout using Filter. Please observe the following code.

1) I have created index.jsp as below,

<body>
<form action="./User">
UserName: <input type="text" name="uname"><br>
Password: <input type="password" name="pwd">
<br>
<input type="submit">
</form>
</body>

2) I have created servlet as below,

public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
HttpSession session = request.getSession();
try {
String uname = request.getParameter("uname");
String pwd = request.getParameter("pwd");
session.setAttribute("uname", uname);
response.sendRedirect("./First.jsp");
} finally {
out.close();
}
}


3) I have created jsp as output as below,

<body>
<%
if(session.getAttribute("uname")!=null){
%>
Welcome <%=session.getAttribute("uname")%>
<%
}
%>
</body>


4) I have created Filter as below,

public class FilterDemo implements Filter {

public FilterDemo() {
}

public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
throws IOException, ServletException {
HttpServletRequest request1 = (HttpServletRequest) request;
HttpServletResponse response1 = (HttpServletResponse) response;

HttpSession session = request1.getSession(false);
try {
System.out.println("Filter Page");
Connection con = null;
PreparedStatement stmt = null;
if (session == null) {
System.out.println("Session Expired");
RequestDispatcher rd = request.getRequestDispatcher("/index.jsp?Expire=yes");
rd.forward(request, response);
}
chain.doFilter(request, response);

} catch (Exception ex) {
ex.printStackTrace();
}
}

public void setFilterConfig(FilterConfig filterConfig) {
}


public void destroy() {
}

public void init(FilterConfig filterConfig) {
}
}


5) web.xml file as below,

<web-app>
<servlet>
<servlet-name>User</servlet-name>
<servlet-class>User</servlet-class>
</servlet>

<filter>
<filter-name>FilterDemo</filter-name>
<filter-class>FilterDemo</filter-class>
</filter>
<filter-mapping>
<filter-name>FilterDemo</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet-mapping>
<servlet-name>User</servlet-name>
<url-pattern>/User</url-pattern>
</servlet-mapping>

<session-config>
<session-timeout>
1
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>





The actual problem of the above code is 'If one minute is complted, the session will be expired...., But it is not redirecting to index.jsp automatically'




Please help me.