JSF将数据存储到cookie中

时间:2011-07-20 14:12:23

标签: jsf cookies

我想将一些用户数据存储到cookie中,以便在加载Web应用程序时始终存在,即使会话已过期。

使用JSF执行此操作的最佳方法是什么?

1 个答案:

答案 0 :(得分:18)

写入Cookie:

FacesContext.getCurrentInstance()
 .getExternalContext()
 .addResponseCookie("CookieName", "value", null);

阅读Cookie

Map<String, Object> requestCookieMap = FacesContext.getCurrentInstance()
   .getExternalContext()
   .getRequestCookieMap();
相关问题