zoukankan      html  css  js  c++  java
  • 04. struts2中Result配置的各种视图转发类型

    概述

    <action name="helloworld" class="com.liuyong666.action.HelloWorldAction">
    	<result name="success">/WEB-INF/page/hello.jsp</result>
    </action>
    
    • result配置类似于struts1中的forward,但struts2中提供了多种结果类型,常用的类型有:
      • dispatcher(默认值)
      • redirect(重定向)
      • redirectAction
      • plainText
    • 通过type属性值指定。

    结果类型

    • redirect

      • 在result中还可以使用${属性名}表达式访问action中的属性,表达式里的属性名对应action中的属性。如下:

      •   <result type="redirect">/view.jsp?id=${id}</result>
        
    • redirectAction

      • 如果重定向的action在同一个包下:

      •   <result type="redirectAction">helloworld</result>
        
      • 如果重定向的action在别的命名空间下:

      •   <result type="redirectAction">
          		<param name="actionName">helloworld</param>
          		<param name="namespace">/test</param>
          </result>
        
    • plainText

      • 显示原始文件内容,例如:当我们需要原样显示jsp文件源代码的时候,我们可以使用此类型。

      •   <result name="source" type="plainText">
          		<param name="location">/xxx.jsp</param>
          		<param name="charSet">UTF-8</param><!-- 指定读取文件的编码 -->
          </result>
        

    全局结果集(Globle Result)

    • 当有多个Action使用同一个结果集时,则可以使用全局结果集(Globle Result),如下:

    •  <global-results> <!-- 定义在包里 -->
        		<result name="mainpage">/main.jsp</result>
       </global-results>
      
    • 多个包想使用同一个结果集,可以利用包的继承,实现代码重用。

      • 创建一个名叫"base"的package,让它继承"struts-default"
      • 该package里放入共用的global-results
      • 想要使用该结果集的包继承"base"

  • 相关阅读:
    字母图形
    IBM CEO罗睿兰:科技公司屹立百年的3个秘诀
    Uva 1331
    js 推断字符串是否包括某字符串
    Verilog堵塞赋值与非堵塞赋值
    tabBar颜色改动
    零基础学python-4.2 其它内建类型
    怎样给你的Android 安装文件(APK)瘦身
    Ambari-部署常见问题
    ops
  • 原文地址:https://www.cnblogs.com/huayonglun/p/14033592.html
Copyright © 2011-2022 走看看