Redirection from filter is not working
<p>I'm trying to redirect my app to the login page in case the session has expired (I have set an interval of 60 minutes). I have created a filter but it seems the redirection is not working properly.</p>

<p>My web.xml:</p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;

&lt;web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1"&gt;
    &lt;session-config&gt;
        &lt;session-timeout&gt;
            60
        &lt;/session-timeout&gt;
    &lt;/session-config&gt;

    &lt;welcome-file-list&gt;
        &lt;welcome-file&gt;login.html&lt;/welcome-file&gt;
    &lt;/welcome-file-list&gt;

    &lt;filter&gt;
        &lt;filter-name&gt;RedirectFilter&lt;/filter-name&gt;
        &lt;filter-class&gt;LoginUtils.RedirectFilter&lt;/filter-class&gt;
    &lt;/filter&gt;
    &lt;filter-mapping&gt;
        &lt;filter-name&gt;RedirectFilter&lt;/filter-name&gt;
        &lt;url-pattern&gt;/AppUtils/*&lt;/url-pattern&gt;
    &lt;/filter-mapping&gt;
&lt;/web-app&gt;
</code></pre>

<p>My filter:</p>

<pre><code>@WebFilter("/AppUtils/*")
public class RedirectFilter implements Filter {

    private ServletContext context;

    public void init(FilterConfig fConfig) throws ServletException {
        this.context = fConfig.getServletContext();
        this.context.log("RedirectFilter initialized");
    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {

        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse res = (HttpServletResponse) response;

        String uri = req.getRequestURI();
        this.context.log("Requested Resource::" + uri);

        HttpSession session = req.getSession(false);
        String loginURL = req.getContextPath() + "/login.html";

        if (session == null &amp;&amp; !req.getRequestURI().equals(loginURL)) {
            this.context.log("Unauthorized access request");
            res.sendRedirect(loginURL);
        } else {
            // pass the request along the filter chain
            chain.doFilter(request, response);
        }

    }

    public void destroy() {
        //no-op
    }

}
</code></pre>