title: sendRedirect not redirecting
body: <p>I'm trying to create a Java controller servlet to log users out of the session. 
  I know there's 2 methods, one by using sendRedirect and the other is RequestDispatcher. In my case, I want to send them to a page outside of the domain, which (to my limited Java knowledge) requires me to use sendRedirect.</p>
  
  <p>However, I'm getting an Error 302 and the page does not get redirected. I have tried a tutorial version and it works, but when I implement it within my Servlet, it returns me the error and does not redirect. </p>
  
  <p>I hope someone could point me in the right direction.</p>
  
  <p>The code I'm using is as below. I'm using the netbeans template:</p>
  
  <hr>
  
  <pre><code>    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
      response.setContentType("text/html;charset=UTF-8");
      PrintWriter out = response.getWriter();
      try {
          HttpSession session = request.getSession(false);
          if (session == null) {
              System.out.println("Invalid");
              response.sendRedirect("http://www.google.com");
              return;
          } else {
              System.out.println("Invalidated");
  
              session.invalidate();
              response.sendRedirect("http://www.google.com");
              return;
              /*
              String url = "/logout.jsp";
  
              ServletContext sc = getServletContext();
              RequestDispatcher rd = sc.getRequestDispatcher(url);
              rd.include(request, response);
  
               */
          }
          /* TODO output your page here
          out.println("&lt;html&gt;");
          out.println("&lt;head&gt;");
          out.println("&lt;title&gt;Servlet LogOut&lt;/title&gt;");  
          out.println("&lt;/head&gt;");
          out.println("&lt;body&gt;");
          out.println("&lt;h1&gt;Servlet LogOut at " + request.getContextPath () + "&lt;/h1&gt;");
          out.println("&lt;/body&gt;");
          out.println("&lt;/html&gt;");
           */
      } finally {            
          out.close();
      }
  }
  </code></pre>
  
  <hr>
  
  <p>Edit: I'm calling the servlet via a <code>&lt;a href&gt;</code> tag. Servlet name is LogOut.java. </p>
  
  <pre><code>        &lt;div data-role="header" data-position="fixed"&gt;
              &lt;h1&gt;Menu&lt;/h1&gt;
              &lt;a href="LogOut" data-theme="i"&gt;Log Out&lt;/a&gt;
          &lt;/div&gt;
  </code></pre>
  
  <p>The doGet and doPost calls the processRequest.</p>
  
  <pre><code>    @Override
  protected void doGet(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
      processRequest(request, response);
  }
  
  /** 
   * Handles the HTTP &lt;code&gt;POST&lt;/code&gt; method.
   * @param request servlet request
   * @param response servlet response
   * @throws ServletException if a servlet-specific error occurs
   * @throws IOException if an I/O error occurs
   */
  @Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
      processRequest(request, response);
  }
  </code></pre>