【Struts框架】第二节Result-结果类型

  • 阿里云国际版折扣https://www.yundadi.com

  • 阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6


    Result类型 
    dispatcher
    redirect
    chain
    redirectAction
    freemarker
    httpheader
    stream
    velocity
    xslt
    plaintext
    tiles
    前四种比较常用

    结果类型实验:

    前台页面:

    <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
    <%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <base href="<%=basePath%>">
    <title>My JSP 'result.jsp' starting page</title>
    </head>

    <body>
    Result类型 <br/>
    <ol>
    <li><a href="<%=basePath %>r/r1">dispatcher</a></li>
    <li><a href="<%=basePath %>r/r2">redirect</a></li>
    <li><a href="<%=basePath %>r/r3">chain</a></li>
    <li><a href="<%=basePath %>r/r4">redirectAction</a></li>
    <li><a href="<%=basePath %>r/rx">redirectAction2</a></li>
    <li>freemarker</li>
    <li>httpheader</li>
    <li>stream</li>
    <li>velocity</li>
    <li>xslt</li>
    <li>plaintext</li>
    <li>tiles</li>
    </ol>
    </body>
    </html>


    struts.xml:


    <?xml version="1.0" encoding="GBK" ?>

    <!DOCTYPE struts PUBLIC
    "-//apache Software Foundation//DTD Struts Configuation 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

    <struts>
    <constant name="struts.devMode" value="true"></constant>
    <constant name="struts.i18n.encoding" value="UTF-8"></constant>

    <package name="resultTypes" namespace="/r" extends="struts-default">
    <!-- 用服务器转发 ,只能跳转到视图(不能是action)-->
    <action name="r1">
    <result type="dispatcher">/r1.jsp</result>
    </action>

    <!-- 用服务器重定向,只能跳转到视图(不能是action)-->
    <action name="r2">
    <result type="redirect">/r2.jsp</result>
    </action>

    <!-- 链条,可以跳转到acion -->
    <action name="r3">
    <result type="chain">r1</result>
    </action>

    <!-- 链条,可以跳转到其他空间的acion -->
    <action name="rx">
    <result type="chain">
    <param name="namespace">/javaee</param>
    <param name="actionName">hello</param>
    </result>
    </action>

    <!-- 客户端跳转到acion -->
    <action name="r4">
    <result type="redirectAction">r2</result>
    </action>
    </package>
    </struts>


    大伙可以根据上面样例实际操作一下,总结之后就明白了Result这几种常见的配置的运行结果

  • 阿里云国际版折扣https://www.yundadi.com

  • 阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6