How can I get session scoped bean in filter from s

2019-07-09 02:50发布

问题:

How can I retrieve session scoped bean in filter? I have tried like that, but it returns null.

this is my session scoped bean:

@SessionScoped
@ManagedBean(name="sessionData")
public class SessionData {
    private UserWrapper userWrapper;

public UserWrapper getUserWrapper() {
    return userWrapper;
}

public void setUserWrapper(UserWrapper userWrapper) {
    this.userWrapper = userWrapper;
}

}

and this is filter:

HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
HttpSession session = httpServletRequest.getSession(false);
if(session != null) {
    SessionData sessionData = (SessionData)session.getAttribute("sessionData");
    System.out.println("sessionData:"+sessionData);
}

Bu it returns null...

sessionData:null;

How can I retrieve sessionData bean in filter?