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");

相关文章:

  • 2021-07-30
  • 2021-12-08
  • 2021-10-08
  • 2022-02-08
  • 2021-09-13
  • 2021-11-02
  • 2022-12-23
  • 2022-02-06
猜你喜欢
  • 2022-12-23
  • 2021-12-16
  • 2022-02-07
  • 2021-12-14
  • 2021-06-01
  • 2021-07-21
  • 2021-04-12
相关资源
相似解决方案