Note: The Portlet spec has this to say about cookies:
PLT.12.1.4 Setting Cookies
A portlet can set HTTP cookies at the response via the addProperty
method with a javax.servlet.http.Cookie
as parameter. The portal
application is not required to transfer the cookie to the client. Thus
the portlet should not assume that it has access to the cookie on the
client or that request triggered with URLs not generated by the
portlet API can access the cookie.
Cookies set in the response of one lifecycle call should be available
to the portlet in the subsequent lifecycle calls, e.g. setting a
cookie in processAction
should enable the portlet to retrieve the
cookie in the next render
call.
For requests triggered via portlet URLs the portlet should receive
back the cookie. Cookies can be retrieved via the request.getCookies
method.
Cookies are properties and all restrictions said above about
properties also apply for cookies, i.e. to be successfully transmitted
back to the client, cookies must be set before the response is
committed. Cookies set in render
or serveResource
after the response
is committed will be ignored by the portlet container.
When setting cookies in the render lifecycle phase portlets should set
the cookies in the render headers part or simply override the
GenericPortlet.doHeaders
method in order to run with maximum
performance on all portal implementations (see PLT.11.1.1.4.3).
Thus, if you literally depend on an HTTP Cookie to be available in the browser: You can't assume that it's there, as it's only a portal internal "property", simulating the behaviour of a cookie.
If you need a Cookie that's available on HTTP/Browser, you'll have to depend on the portal implementation (check it) or set it through Javascript, or find a different solution. If you just need the data to be available, use addProperty
, just as Ankit P mentions in the other answer. I doubt though (due to the spec) that you'll need to get the HttpServletRequest
for it: The cookie should be available on the PortletRequest
(of the portlet originating the request) already.