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
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