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

♀尐吖头ヾ 提交于 2019-11-28 13:06:51

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!