ActionContext類
常用方法
l getContext():返回ActionContext實例對象;
l get(key):相當於HttpServletRequest的getAttribute(String name)方法;
l put(String,Object):相當於HttpServletRequest的setAttribute方法;
l getApplication():返回一個Map對象,存取ServletContext屬性;
l getSession():返回一個Map對象,存取HttpSession屬性;
l getParameters():類似調用HttpServletRequest的getParameterMap()方法 ;
l setApplication(Map):將該Map實例裏key-value保存爲ServletContext的屬性名、屬性值;
l setSession(Map):將該Map實例裏key-value保持爲HttpSession的屬性名、屬性值。
訪問或添加request/session/application屬性
public String execute(){
ActionContext actionContext=ActionContext.getContext();
//往ServletContext中放入app
actionContext.getApplication().put("app", "應用範圍");
//往session中放入ses
actionContext.getSession().put("ses", "session範圍");
//往request中放入req
actionContext.put("req", "request範圍");
return"success";
}