Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JBoss User Help »

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

scott.stark@jboss.org

2007-07-12


"jfrederic.clere@(protected).

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
<%@(protected)" %>
|
| <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
<%@(protected)" %>
| <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
_______________________________________________
jboss-user mailing list
jboss-user@(protected)
https://lists.jboss.org/mailman/listinfo/jboss-user
©2008 junlu.com - Jax Systems, LLC, U.S.A.