【问题标题】:Add non-http only cookie in Liferay在 Liferay 中添加非 http only cookie
【发布时间】:2016-03-12 02:13:12
【问题描述】:

我正在尝试在 Liferay 中添加一个非 http only cookie。这是我在动作课上的尝试

Cookie cookie = new Cookie("testName", "testValue");
cookie.setMaxAge(60 * 60);
cookie.setPath("/");
cookie.setVersion(0);
cookie.setHttpOnly(false);
cookie.setSecure(false);
CookieKeys.addCookie(PortalUtil.getHttpServletRequest(request), PortalUtil.getHttpServletResponse(response), cookie, false);

cookie 已保存,我可以在浏览器的资源视图中看到它,但它只是 http,所以我无法使用 javascript 读取它。知道如何使它成为非 http 的吗?

编辑:

如果我只使用response.addProperty(cookie);,结果是一样的。

这是响应头

Set-Cookie: testName=testValue; Expires=Mon, 07-Dec-2015 15:15:27 GMT; Path=/; HttpOnly

【问题讨论】:

    标签: javascript java tomcat cookies liferay


    【解决方案1】:

    我通过手动设置响应头解决了这个问题

    Calendar ca = Calendar.getInstance();
    ca.add(Calendar.HOUR_OF_DAY, 1);
    String cookieString = "testName=testValue; Expires=" + ca.getTime() + "; Path=/;";
    PortalUtil.getHttpServletResponse(response).setHeader("Set-Cookie", cookieString);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-06-12
      • 2022-08-20
      • 1970-01-01
      • 2017-05-30
      • 2020-12-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-07
      相关资源
      最近更新 更多