如何在HttpServletResponse设置后读取PortletRequest中的cookie?

时间:2014-07-16 18:39:35

标签: java spring-mvc cookies http-redirect ibm-rad

目标:

1)通过HttpServletResponse.addCookie()保存cookie

2)通过HttpServletResponse.sendRedirect()重定向到新的portlet实例。

3)通过PortletRequest在Portlet中读取cookie

问题:

Cookie已设置,可以在FireBug中看到。无法从我的PortletRequest对象中读取cookie。


设置Cookie并重定向:

    @RequestMapping(value = "/setCookie", method = RequestMethod.GET)
public final void setCookie(@RequestParam(value = "cookievalue") String cookieValue, HttpServletRequest request,
        HttpServletResponse response, Model model) {

    Cookie myCookie = new Cookie("cookieName", cookieValue);
    myCookie.setPath("/");
    myCookie.setMaxAge(999999);
    myCookie.setSecure(true);
    response.addCookie(myCookie);

    response.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
    response.setHeader("HeaderName", "/path/to/redirect");
    response.sendRedirect("/path/to/redirect"); //within same domain
}

阅读Cookie

@RequestMapping
public String doView(PortletRequest request, PortletResponse response, Model model) {
    //how do I read my cookie from request?
}

0 个答案:

没有答案