Struts2中五个重要的常量
一.五个常量的位置:位于xwork核心包下的action字节码文件里
二.五个常量的介绍:
a: success
1 public static final string success = "success";
英文注释: the action execution was successful. show result view to the end user. action执行成功,会返回一个结果视图给用户 。
具体用法:
1.action类中:
1 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视图。
上面就是简单的描述。