Struts2..1常用类介绍
Action接口
通过实现Action接口可以快速快发业务控制器Action类,具体的业务逻辑在execute()方法中编写,()可取得ServletContext的引用,进而实现对HttpServletRequest及HttpSession对象的访问。为规范Action处理结果的Result命名,Action接口特定义了5个常用的字符串常量:"ESS","NONE","ERROE","INPUT","LOGIN",
他们可以简化execute方法的返回值,并可以使execute方法的返回值标准化
ActionSupport类
ActionSupport类同时实现了Action接口与Validateable接口,因此通过继承ActionSupport类可以大大简化业务控制器Action类的开发。具体的业务逻辑在execute()方法中编写,数据验证则放置到validate()方法中。除此之外,ActionSupport类为我们提供了大量的实用方法。
addActionError(String anErrorMessage)
addActionMessage(String aMessage)
addFieldError(String fieldName, String errorMessage)
clearErrorsAndMessage()
getActionErrors()
getActionMessages()
getFieldErrors()
getText(String aTextName)
getText(String aTextName, List args)
hasActionErrors()
hasActionMessages()
hasFieldErrors()
ActionContext类
API(HttpServletRequest、HttpSession和ServletContext)提供的工具类,同时也是Struts2中的默认Action类,其常用方法说明如下:
get(Object key):得到HttpServletRequest对象中的指定属性
getContext():返回绑定到当前线程特定的ActionContext
getParameters();得到所有请求参数
getSession()得到一个HttpSession模拟对象
getApplication()得到一个ServletContext模拟对象
setApplication(Map application)将指定Map实例中的key-value对转换到application中
setSession(Map session)将指定Map实例中的key-value对转换到session中
ServletActionContext类
API(HttpServletRequest、HttpSession和ServletContext)提供的工具类,其常用方法说明如下:
g
strurs2.1学习笔记 来自淘豆网m.daumloan.com转载请标明出处.