Get JSF managed bean by name in any Servlet related class

前端 未结 6 637
难免孤独
难免孤独 2020-11-22 01:33

I\'m trying to write a custom servlet (for AJAX/JSON) in which I would like to reference my @ManagedBeans by name. I\'m hoping to map:

http://host

6条回答
  •  执念已碎
    2020-11-22 01:39

    I had same requirement.

    I have used the below way to get it.

    I had session scoped bean.

    @ManagedBean(name="mb")
    @SessionScopedpublic 
    class ManagedBean {
         --------
    }
    

    I have used the below code in my servlet doPost() method.

    ManagedBean mb = (ManagedBean) request.getSession().getAttribute("mb");
    

    it solved my problem.

提交回复
热议问题