Get/set ServletRequest attributes from ActionContext

I need to set a ServletRequest attribute within a Struts2 interceptor (not action class).

Does the ActionContext expose a Map<String, Object> to control request attributes, like it does for session attributes?

I see ActionContext implements a map. Is the ActionContext itself a wrapper for the request attributes?

Answer

For code that is not inside an action class (RequestAware should be used for action classes), Struts2 can expose the servlet request attributes as a Map. They are accessible with:

Map request = (Map) ActionContext.getContext().get("request");

See Strus2 documentation for more details.

Leave a Reply

Your email address will not be published. Required fields are marked *