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?
}