title: java.lang.IllegalStateException on response.SendRedirect("Location")
body: <p>I am a beginner in the world of Java EE. I have been trying to create a simple login System using Servlets and JSP following the guide provided here <a href="http://come2niks.com/?p=1589" rel="noreferrer">http://come2niks.com/?p=1589</a>. 
  This is how my doPost() look like.</p>
  
  <pre><code>@Override
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
          throws ServletException, IOException {
       PrintWriter out = response.getWriter();
      processRequest(request, response);
       try
      {
          System.out.println("In the Login Servlet");
          LoginBean user = new LoginBean();
          user.setUserName(request.getParameter("username"));
          user.setPassword(request.getParameter("pass"));
          LoginDAO db = new LoginDAO();
          user = db.login(user);
  
          System.err.println("I am Back !");
          if(user.isValid())
          {
              System.err.println("VALIDED.. ReDirecting..");
              System.err.println("Getting Session");
              HttpSession session = request.getSession(true);
              System.err.println("Got Session");
              session.setAttribute("currentSessionUser",user);
              System.err.println("Attribute Set");
              response.sendRedirect("Login_Success.jsp");
  
  
          }else
          {
              System.err.println(" NOT VALIDED.. ReDirecting..");
              response.sendRedirect("Login_Failed.jsp");
             out.println(" NOT VALIDED.. ReDirecting.."); 
  
          }
  
  
      } catch (Throwable exc)
      {
          System.out.println(exc);
      }
  }
  </code></pre>
  
  <p>I have added some System.err to get some more info on the flow of the code.</p>
  
  <p>This is what my glassfish says</p>
  
  <pre><code>INFO: In the Login Servlet
  INFO: Driver loaded!
  INFO: Database connected!
  INFO: Welcome Ramesh
  SEVERE: I am Back !
  SEVERE: VALIDED.. ReDirecting..
  SEVERE: Getting Session
  SEVERE: Got Session
  SEVERE: Attribute Set
  INFO: java.lang.IllegalStateException
      at org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:524)
      at groovers.LoginServlet.doPost(LoginServlet.java:100)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:688)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:770)
      at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1550)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:281)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
      at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:655)
      at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:595)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:161)
      at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:331)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:231)
      at com.sun.enterprise.v3.services.impl.ContainerMapper$AdapterCallable.call(ContainerMapper.java:317)
      at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:195)
      at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:860)
      at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:757)
      at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:1056)
      at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:229)
      at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:137)
      at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:104)
      at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:90)
      at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:79)
      at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:54)
      at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:59)
      at com.sun.grizzly.ContextTask.run(ContextTask.java:71)
      at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:532)
      at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:513)
      at java.lang.Thread.run(Thread.java:722)
  </code></pre>
  
  <p>Please help me solve this problem.</p>