title: How to forward a request to non-JSF page in action method?
body: <p>I want to forward request to a non-JSF page from JSF action method.
  I am using below code in my JSF action :</p>
  
  <pre><code>public String submitUserResponse() {
      // ...
  
      parseResponse("foo.jsp", request, response);
  
      // ...
  
      return "nextpage";
  }  
  
  private String parseResponse(String uri, HttpServletRequest request, HttpServletResponse response) {
      if (uri != null) { 
          RequestDispatcher dispatcher = request.getRequestDispatcher(uri);
          dispatcher.forward(request, response);
          return null;
      }
  
      // ...
  
      return "xxxx";
  }
  </code></pre>
  
  <p>The <code>submitUserResponse()</code> action method is being called when user clicks the submit button from the JSF page and this method returns <code>nextpage</code> string. Here the request forwards to next JSF page in normal flow. But in my requirement, I need to forward request to next non-JSF page. It is going, but it is displaying below exception in server.</p>
  
  <blockquote>
    <p>java.lang.IllegalStateException: Cannot forward after response has been committed</p>
  </blockquote>
  
  <p>I observed that code lines between <code>parseResponse(...)</code> and <code>return "nextpage";</code> are still being executed after forwarding my request using <code>dispatched.forward(uri)</code>. Same thing happened with <code>response.sendRedirect(url)</code>. How is this caused and how can I solve it?</p>