title: Problems with sendRedirect() function
body: <p>I have this strange problem with sendRedirect function which i can't explain.
  I have a <strong>header page</strong> as Header.jsp as :</p>
  
  <pre><code>&lt;%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*,java.util.*" errorPage="" %&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;title&gt;Online Exam Portal&lt;/title&gt;
  &lt;style type="text/css"&gt;
      body{
          background-color : lightgreen;
      }
      &lt;/style&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;%
  if(session.getAttribute("userid")==null)
  {
     response.sendRedirect("signup.html");
  }
  %&gt;
  &lt;img src="exam_header01.jpg"/&gt;
  &lt;br /&gt;
  Welcome &lt;%=session.getAttribute("userid")+"This is Working"%&gt;
  &lt;a href="ChangePassword.jsp"&gt;Change Password&lt;/a&gt; 
  &lt;a href="logout.jsp"&gt;Logout&lt;/a&gt; 
  
  &lt;hr/&gt;
  </code></pre>
  
  <p>i have <strong>included</strong> this header page in all the pages, i did this since i wanted to prevent the users who don't have valid session and redirect to signup page but it <strong>doesn't redirects</strong>
  instead it shows Welcome null and also :<br/>
  1> If i write anything inside that if statement it works fine! , like :</p>
  
  <pre><code>if(session.getAttribute("userid")==null)
  {
     response.sendRedirect("signup.html");//this is not executed
     out.println("This Runs");//this String is printed
  }
  </code></pre>
  
  <p>2> If i write the same code inside the main page(i.e after header page) it works fine!<br/>
  3> And most importantly the code works when i replace it by :</p>
  
  <pre><code>&lt;jsp:forward page="signup.html"/&gt;
  </code></pre>
  
  <p>What could be the problem here. it would be really appreciated if anyone can explain with examples.
  <hr/>
  Update :-
  Even If i print to my page after Redirect it will work if i use if statement use after including the Header :</p>
  
  <pre><code>&lt;jsp:include page="Header.jsp"/&gt;
          &lt;%if(session.getAttribute("userid")==null)
  { 
  response.sendRedirect("signup.html");
  out.println("I cant See this because page is redirected ");
  } 
  %&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>