I can get property from a session attribute, but not from a session map

前端 未结 1 960
悲&欢浪女
悲&欢浪女 2020-12-11 13:03

I am using SSH2. When I try to got an attribute with <%=session.getAttribute(\"username\") %>, it was just right. But when I tried to get the same attrib

相关标签:
1条回答
  • 2020-12-11 13:35

    Yes, they are not the same, in the scriptlet you use the http session implicit object, in the struts tag attribute you reference the struts session map object, retrieved via OGNL. You got nothing just because they are different. To use the struts session map you should implement SessionAware in the action. So, the servlet config interceptor will inject the session to it, then you could use the session map to put there values, that will be accessible via OGNL.

    The example of SessionAware implementation:

    private Map<String, Object> session;
    
    @Override
    public void setSession(Map<String, Object> session) {
     this.session = session;
    } 
    

    lazy initialization exception happens because you didn't implement toString in the model entities.

    See Accessing application, session, request objects

    0 讨论(0)
提交回复
热议问题