JSF

When you have to access your Managed Bean in a servlet, it depends on the scope you set for the Bean.

Request-Scope:

HttpServletRequest httpRequest =(HttpServletRequest) request;YourBean bean =(YourBean) request.getAttribute("yourBean");

Session-Scope:

HttpServletRequest httpRequest =(HttpServletRequest) request;HttpSession httpSession = httpRequest.getSession();YourBean bean =(YourBean) httpSession.getAttribute("yourBean");

Application-Scope:

HttpServletRequest httpRequest =(HttpServletRequest) request;HttpSession httpSession = httpRequest.getSession();ServletContext ctx = httpSession.getServletContext();YourBean bean =(YourBean) ctx.getAttribute("yourBean");
原文地址:https://www.cnblogs.com/sos-blue/p/3385831.html