title: Is it possible to forward or redirect from a servlet filter after the response has been committed?
body: <p>The logic is that the filter gets hit, the condition is not true, so it goes through the filter chain. After the response is committed, the filter gets hit, and the condition is now true (a request attribute was set). It goes in to execute the forward, but the page never forwards. I know this has something to do with the response being committed because I tested different logic where it forwards before it hits the chain for the first time, and it does forward successfully.</p>
  
  <pre><code>public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
              throws IOException, ServletException {
  
      HttpServletRequest httpServletRequest = (HttpServletRequest)request;
  
      if (some condition equals true) {
          httpServletRequest.getRequestDispatcher("/home.jsp").forward(request, response);
          return;
      } else {
          chain.doFilter(request, response);
      }
  }
  </code></pre>
  
  <p>Example from my deployment descriptor:</p>
  
  <pre><code>&lt;filter&gt;
      &lt;filter-name&gt;MyFilter&lt;/filter-name&gt;
      &lt;filter-class&gt;com.filters.MyFilter&lt;/filter-class&gt;
  &lt;/filter&gt;
  
  &lt;filter-mapping&gt;
      &lt;filter-name&gt;MyFilter&lt;/filter-name&gt;
      &lt;url-pattern&gt;*.jsp&lt;/url-pattern&gt;
      &lt;dispatcher&gt;REQUEST&lt;/dispatcher&gt;  
      &lt;dispatcher&gt;FORWARD&lt;/dispatcher&gt; 
  &lt;/filter-mapping&gt;
  </code></pre>