[jboss-user] [Tomcat, HTTPD, Servlets & JSP] - Re: Cookies lost when included JSP file used

weisinger do-not-reply at jboss.com
Thu Jul 12 15:25:56 EDT 2007


"jfrederic.clere at jboss.com" wrote : The cookies in the included JSP pages are ignored.

You're right.  I see that under the JSP spec description for the include directive:

http://sdlc-esd.sun.com/ESD24/JSCDL/jsp/2.1-fr/jsp-2_1-fr-spec.pdf?AuthParam=1184259549_291d84a0dc93c8ab5a265e4374e74aa3&TUrl=an1npDpbKod7kSYrROhENTonIeY4W0D1Lc4nXz+pGFFranixdCdgxDTPbW4=&TicketId=dVB+OQJINeg7/Q==&GroupName=SDLC&BHost=sdlc6g.sun.com&FilePath=/ESD24/JSCDL/jsp/2.1-fr/jsp-2_1-fr-spec.pdf&File=jsp-2_1-fr-spec.pdf
anonymous wrote : An included page cannot change the response status code or set headers. This precludes invoking methods like setCookie. 
  | Attempts to invoke these methods will be ignored. 
  | The constraint is equivalent to the one imposed on the include method of the RequestDispatcher class.

The workaround seems to be to have the base jsp file create the cookies.
But doing that also seems to fail.  Flipping around the example files I used above, the following also fails to create the cookie.  Just including the file seemed to cause it to fail to create the cookie. 

          jsptest.jsp
<%@ page contentType="text/html" %>
  | 
  | <jsp:include page="./cookietest.jsp" flush="true"/>
  | 
  | <jsp:directive.page import="javax.servlet.http.Cookie"/>
  | <jsp:scriptlet><![CDATA[
  |    Cookie c = new Cookie("NewCookie","Data for Cooki");
  |    out.println(c.getName()+": "+c.getValue()+"<br/>");
  |    response.addCookie(c);
  | ]]></jsp:scriptlet>
  | 
  | <html><body>
  | <center><b>JSP Test</b></center>
  | </body></html>

          cookietest.jsp
<%@ page contentType="text/html" %>
  | <html><body>
  | <p>
  | Hello from included page.
  | </p>
  | </body></html>

After commenting out the include, the cookies show up.
Is this what I should expect?  Is there something else that I need to do?

<!-- jsp:include page="./cookietest.jsp" flush="true"/ -->

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4063691#4063691

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4063691



More information about the jboss-user mailing list