title: How to set a Cookie in Liferay portlet?
body: <p>I am having problems of trying to set a session cookie(s) in <strong>Liferay 6.0 portlets</strong>. I want to be able to set a cookie to the client browser to store application key for the linkedin authentication, where it can be then retrieved by other portlets.</p>
  
  <p>I am able to read cookies by using a following:</p>
  
  <pre class="lang-java prettyprint-override"><code>public void addLinkedInCV(ActionRequest request, ActionResponse response)
          throws PortalException, SystemException {
  
      HttpServletRequest convertReq = PortalUtil.getHttpServletRequest(request);
      Cookie[] cookies = convertReq.getCookies();
      ...
  }
  </code></pre>
  
  <p>Here's my failed attempt to read one.</p>
  
  <pre class="lang-java prettyprint-override"><code>@Override
  public void doView(RenderRequest renderRequest,RenderResponse renderResponse) throws IOException, PortletException {
  
      HttpServletResponse convertRes = PortalUtil.getHttpServletResponse(renderResponse);
      HttpServletResponse originalRes = (HttpServletResponse) ((HttpServletResponseWrapper) convertRes).getResponse();
  
      Cookie linkedInCookie = new Cookie("linkedIn", util.getAppKey());
      originalRes.addCookie(linkedInCookie);
  }
  </code></pre>