Reputation: 969
I trying to add cookie from portlet using
HttpServletResponse response=PortalUtil.getHttpServletResponse(renderResponse);
Cookie cookie=new Cookie("abc","123");
response.addCookie(cookie);
But when i am trying to print value for this cookie i am not able to find this cookie. Can anyone suggest me the solution for this?
Upvotes: 0
Views: 4431
Reputation: 2257
Not so easy discover how to use a cookie in your portlet,
This cose sample is ok and is written within the portlet render code.
Use the RenderResponse
, not the HttpServletResponse
.
import com.liferay.util.CookieUtil;
Cookie cookie = new Cookie("name", value);
renderResponse.addProperty(cookie);
And to read the cookie from the request:
HttpServletRequest request = PortalUtil.getHttpServletRequest(
portletRequest);
orderCartNumber = CookieUtil.get(request, "name");
bye
Upvotes: 1