title: Servlet: Cannot forward after response has been committed
body: <p>I'm working on servlet page that renders content based on <code>geo-location</code>, and I want to use both <code>sendRedirect</code> and <code>forward</code> together; e.g; you browse <code>example.com/aPage.jsp</code> from <code>France</code>; first I want the servlet to redirect you to <code>example.com/fr/aPage.jsp</code> and then forward you to the <code>resources</code> page.</p>
  
  <p>This is what I have in my servlet:</p>
  
  <pre><code>public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    ....
    response.sendRedirect(REDIRECT_URL_BASED_ON_GEO);
    // after redirect forward the resources page
    RequestDispatcher view = request.getRequestDispatcher(RESOURCES_PAGE);
    view.forward(request, response);
    ...
  }
  </code></pre>
  
  <p>But I get:</p>
  
  <pre><code>java.lang.IllegalStateException: Cannot forward after response has been committed
  </code></pre>
  
  <p><strong>I know the error appears because</strong> I can't use both <code>sendRedirect</code> and <code>forward</code> one after another, but I don't know how to achieve what I want (as described above) without this.</p>
  
  <p>any help?</p>