Struts2中Action配置的默认值和result配置的转发类型

来源:互联网 发布:微信 换手机 数据迁移 编辑:程序博客网 时间:2024/06/05 19:00

1、Action配置的各项默认值
      (1)如果没有为action指定class,默认是ActionSupport。
      (2)如果没有为action指定method,默认执行action中的execute()方法。
      (3)如果没有为action指定result,默认值为success。

2、result配置的各种转发类型
      <result type="velocity-layout">${theme}/Site/PayShow.vm</result>
      其中type的常用类型有:
      dispatcher(默认值) ->转发
      redirect ->重定向
      redirectAction->重定向的action在别的命名空间下
      如:<result type="redirectAction">
                  <param name="actionName">helloworld</param>
                  <param name="nameSpace">/test</param>
            </result>
      如:<result type="">
                  <param name="location">/xxx.jsp</param>
                  <!--指定读取文件的编码-->
                  <param name="charSet">UTF-8</param>
            </result>

3、几种较特殊的action和result转发
<package name="helloWord"  namespace="/helloWord"  extends="base">

       <!-- 访问路径:http://localhost/helloWord/manage.action -->
             <action name="manage"  class="com.ljq.action.HelloWordAction"  method="msg"></action>
       <!-- 访问路径:http://localhost/helloWord/listHelloWord.action
                               http://localhost/helloWord/msgHelloWord.action 
-->
             <action  name="*HelloWord"  class="com.ljq.action.HelloWordAction"  method="{1}"></action>

       <!--注意:在result中可以使用${属性名}访问action中的属性,属性名对应action中的属性-->
             <result name="list" type="redirect">/index.jsp?username=${username}</result>
</package>

原创粉丝点击