Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

You can obtain the session attributes by asking the ActionContext or implementing SessionAware. Implementing SessionAware is preferred.

Ask the ActionContext

The session attributes are available on the ActionContext instance, which is made available via ThreadLocal.

Code Block
Map attibutes = ActionContext.getContext().getSession();

Implement SessionAware

(star) _Preferred_

  • Ensure that servlet-config Interceptor is included in the Action's stack.
    • (info) The default stack already includes servlet-config.
  • Edit the Action so that it implements the SessionAware interface.
    • The SessionAware interface expects a setSession method. You may wish to include a companion getSession method.
  • At runtime, call getSession to obtain a Map representing the session attributes.
  • Any changes made to the session Map are reflected in the actual HttpSessionRequest. You may insert and remove session attributes as needed.

...