You can obtain the session attributes by implementing SessionAware
or getting them from the ActionContext
.
SessionAware
This is the preferred mechanism: it makes unit testing easier by allowing simple injection of session attributes instead of having to mock the action context or go through an entire request process.
servletConfig
interceptor.servletConfig
.SessionAware
interface.SessionAware
interface defines a setSession
method that sets the session attributes into the action.HttpSession
. You may query, insert, and remove session attributes as needed.
The |
To unit test a |
Session attributes are available from the ActionContext
instance, a ThreadLocal
.
Map attibutes = ActionContext.getContext().getSession(); |
@see struts-default.xml
@see org.apache.struts.acton2.interceptor.SessionAware
@see org.apache.struts.acton2.interceptor.ServletConfigInterceptor