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,

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

2) I have created servlet as below,

public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
HttpSession session = request.getSession();
try {
String uname = request.getParameter("uname");
String pwd = request.getParameter("pwd");
session.setAttribute("uname", uname);
} finally {

3) I have created jsp as output as below,

Welcome <%=session.getAttribute("uname")%>

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) {

public void setFilterConfig(FilterConfig filterConfig) {

public void destroy() {

public void init(FilterConfig filterConfig) {

5) web.xml file as below,




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.