I have used the following code to set cookie and then redirect.
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");
}
This code works fine. But I want to know how? Because when the jsp engine is parsing the jsp code, it will first encounter addCookie
and the send redirect. Does it add the cookie as soon as the line response.addCookie(cookie);
? What if I give it the other way round i.e first sendRedirect()
and then addCookie()
? How does the jsp engine see this?