ActionContext的介绍
2011-12-19 09:35
183 查看
在Struts2.0中,Action已经与Servlet API完全分离,这使得Struts2.0的Action具有了更加灵活和低耦合的特性,与Struts1.0相比较而言是个巨大的进步。虽然Struts2.0的Action已经与Servlet API完全分离,但我们在实现业务逻辑处理时经常需要访问Servlet中的对象,如Session、Application等。Struts2.0 提供了一个名字为ActionContext的类,在Action中可以通过该类获得Servlet API。
ActionContext是一个Action的上下文对象,Action运行期间所用到的数据都保存在ActionContext中(如Session,客户端提交的参数等信息)。
在Action中可以通过下面的代码来创建和使用ActionContext类,关于该类的方法介绍如下所示:
ActionContext ac=ActionContext.getContext();
以下是ActionContext类的常用方法
1.Object get(Object key) :通过参数key来查找当前ActionContext中的值
2.Map getApplication() :返回一个Application级的Map对象
3.Static ActionContext getContext() :获得当前线程的ActionContext对象
4.Map getParameters() :返回一个包含所有HttpServletRequest参数信息的Map对象
5.Map getSession() :返回一个Map类型的HttpSession对象
6.Void put(Object key,Object value) :向当前ActionContext对象中存入名值对信息
7.Void setApplication(Map application) :设置Application上下文
8.Void setSession(Map session) :设置一个Map类型的Session值
ActionContext是一个Action的上下文对象,Action运行期间所用到的数据都保存在ActionContext中(如Session,客户端提交的参数等信息)。
在Action中可以通过下面的代码来创建和使用ActionContext类,关于该类的方法介绍如下所示:
ActionContext ac=ActionContext.getContext();
以下是ActionContext类的常用方法
1.Object get(Object key) :通过参数key来查找当前ActionContext中的值
2.Map getApplication() :返回一个Application级的Map对象
3.Static ActionContext getContext() :获得当前线程的ActionContext对象
4.Map getParameters() :返回一个包含所有HttpServletRequest参数信息的Map对象
5.Map getSession() :返回一个Map类型的HttpSession对象
6.Void put(Object key,Object value) :向当前ActionContext对象中存入名值对信息
7.Void setApplication(Map application) :设置Application上下文
8.Void setSession(Map session) :设置一个Map类型的Session值
相关文章推荐
- 上下文(context)ActionContext介绍(在Struts2中)
- ActionContext介绍
- ActionContext的介绍
- Struts2中ActionContext及ServletActionContext介绍(转载)
- 上下文(context)ActionContext介绍(在Struts2中)
- Spring AppliactionContext功能介绍
- ActionContext和ServletActionContext介绍
- Struts2中ActionContext介绍
- 上下文(context)ActionContext介绍(在Struts2中)
- struts2 中的ActionContext的介绍
- 传智播客--struts2.x的ActionContext,ValueStack和常用标签介绍
- Struts2中ActionContext介绍
- struts2.x的ActionContext,ValueStack和常用标签介绍
- ActionContext的介绍
- ActionContext的介绍
- ActionContext的介绍
- 在struts2中关于ActionContext介绍
- ActionContext和ServletActionContext小结
- ServletActionContext.getServletContext().getRealPath("/upload");myeclipseyeclipse获取路径不一样的原因
- There is no Action mapped for namespace [/] and action name [login] associated with context path [/M