-
1. Re: Cookies lost when included JSP file used
jfclere Jul 12, 2007 8:58 AM (in response to weisinger)That is because of JSP spec's requirement.
-
2. Re: Cookies lost when included JSP file used
weisinger Jul 12, 2007 10:56 AM (in response to weisinger)"jfrederic.clere@jboss.com" wrote:
That is because of JSP spec's requirement.
Could you be more specific?
Is it not possible at all to create cookies on a JSP page that include another JSP page?
Thanks -
3. Re: Cookies lost when included JSP file used
jfclere Jul 12, 2007 11:23 AM (in response to weisinger)The cookies in the included JSP pages are ignored.
-
4. Re: Cookies lost when included JSP file used
weisinger Jul 12, 2007 3:25 PM (in response to weisinger)"jfrederic.clere@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.pdfAn 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"/ -->
-
5. Re: Cookies lost when included JSP file used
jfclere Jul 13, 2007 4:16 AM (in response to weisinger)flush="true"
That flushes the header and the cookies too early.
Remove it or use flush="false". -
6. Re: Cookies lost when included JSP file used
weisinger Jul 13, 2007 11:27 AM (in response to weisinger)After doing that it works.
But it's too bad that it isn't possible to bring forward the cookies created by the included page.
Thanks for your help. -
7. Re: Cookies lost when included JSP file used
weisinger Jul 13, 2007 5:50 PM (in response to weisinger)Unfortunately, there's still a problem.
I now understand the results of the test case above using included jsp files.
What I'm working on though uses Coldfusion cfm files.
I thought that I had replicated the same problem with just JSP pages, so that was what I originally reported.
In the JSP page, I'd like to include a cfm file, like the following:<jsp:include page="../../../app/Application.cfm" flush="false" />
Below that include, I have the scriptlet code to create a cookie in the JSP.
If I comment out the include, the cookie is created.
When the include is used, the cookie doesn't show up.
flush is turned off.
Is there still something else I must do to get cookies to show up?
If this is a bug, is it one within JBoss or ColdFusion?
Thanks -
8. Re: Cookies lost when included JSP file used
raist_majere Oct 6, 2007 12:47 AM (in response to weisinger)You should use a page directive specifying a greater buffer size. Take a look at the spec:
buffer
Specifies the buffering model for the initial out JspWriter to
handle content output from the page.
If none, then there is no buffering and all output is written
directly through to the ServletResponse PrintWriter.
The size can only be specified in kilobytes. The suffix kb is
mandatory or a translation error must occur.
If a buffer size is specified then output is buffered with a
buffer size not less than that specified.
Depending upon the value of the autoFlush attribute, the
contents of this buffer is either automatically flushed, or an
exception is raised, when overflow would occur.
The default is buffered with an implementation buffer size of
not less than 8kb.
autoFlush
Specifies whether the buffered output should be flushed
automatically (true value) when the buffer is filled, or
whether an exception should be raised (false value) to
indicate buffer overflow. It is illegal, resulting in a translation
error, to set autoFlush to false when buffer=none. The default
value is true
addCookie sets a header, which cannot be done once the page is flushed.