+

Search Tips   |   Advanced Search

Set cookies for a JSR 286 portlet


Although cookies can be set like any other HTTP header, the portlet API provides the addProperty convenience method on the PortletResponse for setting cookies.

Invoke the addProperty method to set cookies.

When setting cookies, you must invoke the addProperty method before the response headers are committed. This should occur no later than during the render headers sub phase of the render lifecycle phase.

Example:

protected void doHeaders(RenderRequest request, RenderResponse response)
{
    ...      Cookie c = new Cookie("myCookieName", "myCookieValue");
    c.setPath(request.getContextPath());
    response.addProperty(c);
    ...
}


Parent: Use two-phase rendering with JSR 286 portlets