首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >struts2 Result Type四个常用转跳类型

struts2 Result Type四个常用转跳类型

作者头像
lpxxn
发布2018-01-31 13:27:43
5320
发布2018-01-31 13:27:43
举报
文章被收录于专栏:技术之路技术之路技术之路

Result的四个常用转跳类型分别为

Dispatcher    用来转向页面,是Struts的默认形式

Redirect       重定向到一个URL

Chain       用来处理Action链 

RedirectAction     重定向到一个Action

还有以下几种不太常用

freemaker:  处理FreeMarker模板   

httpheader:  控制特殊HTTP行为的结果类型  

stream:      向浏览器发送InputSream对象,用来处理文件下载,还可用于返回AJAX数据   

velocity :    处理Velocity模板   

xsl:             处理XML/XLST模板   

plaintext:   显示原始文件内容,例如文件源代码   

这里只说最常用的4种

看一下struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>
    <!-- Add packages here -->
     <constant name="struts.devMode" value="true" />
    <constant name="struts.enable.DynamicMethodInvocation" value="true"/>
    <package name="default" namespace="/" extends="struts-default">        
        <action name="add1" >
            <result type="dispatcher">
                /Oneaddok.jsp
            </result>                    
        </action>
        <action name="add2" >
            <result type="redirect">
                /Oneeditok.jsp
            </result>                    
        </action>
        <action name="add3" >
            <result type="chain">
                add1
            </result>                    
        </action>
        <action name="add4">
            <result type="redirectAction">
                add2
            </result>                     
        </action>
    </package>
</struts>

再看一个jsp页面

<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%
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 'Index.jsp' starting page</title>
    
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

  </head>
  
  <body>
    This is my JSP page. <br>
    <li><a href="add1">Dispatcher</a></li>
    <li><a href="add2">Redirect</a></li>
    <li><a href="add3">Chain</a></li>
    <li><a href="add4">RedirectAction</a></li>
  </body>
</html>

就是这么简单,自己动手试一下吧

 源代码:Struts15AccessResultType.rar

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2014-06-16 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档