欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

Struts2中五个重要的常量

发布时间:2025/7/14 编程问答 52 豆豆
生活随笔 收集整理的这篇文章主要介绍了 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视图。

 

上面就是简单的描述。

                                                                                                                                                                                                                                                                                                                      

 

转载于:https://www.cnblogs.com/ends-earth/p/10701772.html

总结

以上是生活随笔为你收集整理的Struts2中五个重要的常量的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。