[opencms-dev] Unable To Set Cookies In Page Elements

Stephan Hartmann hartmann at metamesh.de
Wed Feb 10 09:57:02 CET 2010

Cookies require modification of response headers.
As per definition of the servlet spec, you cannot modify response headers
from within a servlet or JSP that is included with a request dispatcher (or
after there have been already written some bytes to the output stream).

You can only modify response headers in the most top servlet / JSP or if the
request is forwarded.


2010/2/10 Brett Sheeran <brett.sheeran at gmail.com>

> Hi,
> I find that code for setting cookies inside a page element does not
> succeed.
> Here is some simple code placed inside an element:
> -----
>     Cookie cookie = new Cookie ("ELEMENT_COOKIE", "value1");
>     cookie.setMaxAge(31536000);//secs in a year
>     cookie.setPath("/");
>     response.addCookie(cookie);
> -----
> There are no errors, but *definitely* no cookies either. I checked
> using both request.getCookies(); and the show cookies button in my
> Safari browser.
> However, the previous code *will* work if placed inside the template
> JSP that calls the page element.
> Furthermore, the Following code does not work in a page element either.
>     CmsRequestUtil.setCookieValue(cms, "ELEMENT_COOKIE2", "value2");
> Any suggestions?
> Thank you.
> Regards Brett Sheeran
> _______________________________________________
> This mail is sent to you from the opencms-dev mailing list
> To change your list options, or to unsubscribe from the list, please visit
> http://lists.opencms.org/mailman/listinfo/opencms-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20100210/fca2837b/attachment.htm>

More information about the opencms-dev mailing list