title: response with a addCookie() and send Redirect()
body: <p>I have used the following code to set cookie and then redirect.</p>
  
  <pre><code>String level=(String) request.getAttribute("level");
  
   if(level!=null)
   {
    Cookie cookie=new Cookie("level",level);
    cookie.setMaxAge(-1);
    cookie.setPath("http://localhost:8080/saml");
  
    response.addCookie(cookie);
  
    response.sendRedirect("http://​localhost:8080/saml/someservices.jsp");
   }
  </code></pre>
  
  <p><br>
  This code works fine. But I want to know how? Because when the jsp engine is parsing the jsp code, it will first encounter <code>addCookie</code> and the send redirect. Does it add the cookie as soon as the line <code>response.addCookie(cookie);</code> ? What if I give it the other way round i.e first <code>sendRedirect()</code> and then <code>addCookie()</code>? How does the jsp engine see this?</p>