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");
posted on 2013-10-24 12:54  七月逆流  阅读(297)  评论(0编辑  收藏  举报