一.五个常量的位置:位于xwork核心包下的Action字节码文件里
二.五个常量的介绍:
a: SUCCESS
public static final String SUCCESS = "success";
英文注释: The action execution was successful. Show result view to the end user. action执行成功,会返回一个结果视图给用户 。
具体用法:
1.action类中:
public String execute() throws Exception {
2 return SUCCESS;
3 }
struts.xml文件:result标签默认就是success,所以可以省略,这里面默认的name="success",底层会自动帮你找寻返回值为success,并为其跳转到对应的视图界面
<result type="redirect">item.jsp</result>
b: NONE
public static final String NONE = "none";
英文解释:The action execution was successful but do not show a view. This is useful for actions that are handling the view in another fashion like redirect.
action执行是成功的,但是不会显示界面(视图),这对于以另一种重定向方式处理视图是有用的。简单说就是不让跳转到其他界面
具体用法:
public String execute() throws Exception {
return NONE;
}
c: ERROR
public static final String ERROR = "error";
英文解释:The action execution was a failure.Show an error view, possibly asking the user to retry entering data.
action执行失败了,跳转显示一个错误视图,可能请求用户再次输入相关数据。也就是说,当anction返回结果fail或者其他失败,会帮你跳转到错误信息对于的视图
具体用法:
//action类:
public String execute() throws Exception {
//条件代码
return ERROR;
} //struts.xml
<result name="error" type="redirect">item.jsp</result>
d: LOGIN
public static final String LOGIN = "login";
英文解释:The action could not execute, since the user most was not logged in. The login view should be shown.
这个anction不能执行,由于用户没有登录 ,该登录视图可能会被显示。也就是说登录出错页面跳转
//action类:
public String execute() throws Exception {
//条件代码
return LOGIN;
} //struts.xml
<result name="login" type="redirect">login.jsp</result>
e: INPUT ***
public static final String LOGIN = "input";
英文:The action execution require more input in order to succeed.This result is typically used if a form handling action has been executed so as to provide defaults for a form. Theform associated with the handler should beshown to the end user.<p/>This result is also used if the given input params are invalid, meaning the user should try providing input again.
这个action为了成功需要多次输入,如果一个表单表单处理action操作被执行,便会为表单提供默认表单,通常会使用此结果。这个表单会显示给最终用户,这个结果也被用来用户输入无效,这意味着用户需要在输入一遍
上面五个变量其中除了input,其他都可以使用自定义的,只有input不能改,input视图在某些拦截器中使用,如数据校验,类型转化等等都可能出现错误,这些错误在struts2中专门放在数据存储区域的错误信息区域,struts2再走到最后一个workflow拦截器种会检查错误区域是否有错误信息,如果有,跳转到input视图。
上面就是简单的描述。