ActionContext

来源:互联网 发布:电脑顽固软件卸载 编辑:程序博客网 时间:2024/06/05 05:16

一、定义

ActionContext是Action的上下文,Struts2自动在其中保存了一些在Action执行过程中所需的对象,比如session, parameters, locale等。Struts2会根据每个执行HTTP请求的线程来创建对应的ActionContext,即一个线程有一个唯一的ActionContext。因此,使用者可以使用静态方法ActionContext.getContext()来获取当前线程的ActionContext。

二、方法简介

(1)static ActionContext getContext()
          Returns the ActionContext specific to the current thread.

(2)Map<String,Object>   getParameters()
          Returns a Map of the HttpServletRequest parameters when in a servlet environment or a generic Map of parameters otherwise.

(3)Map<String,Object>  getSession()
          Gets the Map of HttpSession values when in a servlet environment or a generic session map otherwise.

(4)Map<String,Object>  getApplication()
          Returns a Map of the ServletContext when in a servlet environment or a generic application level Map otherwise.

(4)ValueStack     getValueStack()
          Gets the OGNL value stack.

(5)void    put(String key, Object value) 
          Stores a value in the current ActionContext.

(6)Object  get(java.lang.String key)
          Returns a value that is stored in the current ActionContext by doing a lookup using the value's key.

原创粉丝点击