从ActionContext获取/设置ServletRequest属性 [英] Get/set ServletRequest attributes from ActionContext
问题描述
我需要在Struts2拦截器(不是动作类)中设置 ServletRequest
属性。 ActionContext
是否公开 Map< String,Object>
来控制请求属性,就像会话属性一样?
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?
我看到 ActionContext
实现了一个地图...是 ActionContext
本身是请求属性的包装器?
I see ActionContext
implements a map... is the ActionContext
itself a wrapper for the request attributes?
推荐答案
对于不在动作类中的代码( RequestAware
应该用于动作类),Struts2可以将servlet请求属性公开为Map。它们可以通过以下方式访问:
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");
参见 Strus2文档了解更多详情。
这篇关于从ActionContext获取/设置ServletRequest属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!