下面的代码片段就是我正在使用的内容.
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
Map<String, Object> sessionMap = externalContext.getSessionMap();
sessionMap.put("User",user);
Run Code Online (Sandbox Code Playgroud)
现在我怎么能从普通的"servlet"获得"sessionMap" - "key"值?这样的代码是否(User)session.getAttribute("User");可以通过我的servlet工作?
在servlet中,请求/会话/应用程序属性是来自doGet(HttpServletRequest request, HttpServletResponse response)/ doPost(HttpServletRequest request, HttpServletResponse response)methods 中的availbale :
//request attributes
String string = (String)request.getAttribute("username");
//session attributes
String string = (String)request.getSession().getAttribute("username");
//application attributes
String string = (String)getServletContext().getAttribute("beanName");
Run Code Online (Sandbox Code Playgroud)
当请求由the处理时FacesServlet,属性可用作:
//request attributes
String string = (String)FacesContext.getCurrentInstance().getExternalContext().getRequestMap().get("username");
//session attributes
String string = (String)FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("username");
//application attributes
String string = (String)FacesContext.getCurrentInstance().getExternalContext().getApplicationMap().get("username");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2749 次 |
| 最近记录: |