struts2 result type= redirect redirectAction chain dispatcher等类型

本文主要是介绍struts2 result type= redirect redirectAction chain dispatcher等类型,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

struts.xml




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


<!-- 
总结
dispatcher 可以转发到web-inf目录(默认)
redirect 不能重定向到web-inf目录
chain链式转发  不用写param传递参数,系统会自动把上次的参数保存传递
redirect只能重定向到本namspace的action ,这里不能使用param属性
redirectAction可重定向到其他namspace的action ,这里必须用type="redirectAction”
plainText源码显示
 -->

<struts>
 
    <constant name="struts.devMode" value="true" />
<package name="struts1" namespace="/" extends="struts-default" >

<!-- dispatcher 可以转发到web-inf目录(默认) -->
  <action name="dispatcher_to_webinf" class="action.TiaoZhuan"  method="dispatcher">
<result name="dispatcher">
 /WEB-INF/web-inf.jsp
</result>
</action>
<!-- redirect 不能重定向到web-inf目录 -->
 <action name="redirect_to_webinf" class="action.TiaoZhuan"  method="redirect">
<result name="redirect" type="redirect">
 /WEB-INF/web-inf.jsp
</result>
</action>

<!--第一种  带参数重定向  直接写在链接里-->
 <!-- <action name="param_redirect" class="action.TiaoZhuan"  method="param_redirect">
<result name="param_redirect" type="redirect">
  /index1.jsp?id=${id}
 <param name="userName1">${userName1}</param>
</result>
</action>
-->
<!--第二种 带参数重定向  在param中写  -->
<action name="param_redirect" class="action.TiaoZhuan"  method="param_redirect">
<result name="param_redirect" type="redirect">
 <param name="location">/index1.jsp</param>
 <param name="id">${id}</param>
</result>
</action>

 <!-- chain链式转发  不用写param传递参数,系统会自动把上次的参数保存传递-->
<action name="chain" class="action.TiaoZhuan"  method="chain">
<result name="chain" type="chain">
 <param name="actionName">chain1</param>
<!--  <param name="userName">${userName}</param>
      <param name="userName1">${userName1}</param>
  -->
</result>
</action>
<action name="chain1" class="action.TiaoZhuan"  method="chain1">
<result name="chain1">
 /index1.jsp
</result>
</action>

<!-- redirect只能重定向到本namspace的action ,这里不能使用param属性-->
<action name="redirectAction" class="action.TiaoZhuan"  method="redirectAction">
<result name="redirectAction" type="redirect">
   dispatcher_to_webinf
</result>
</action>


<!-- redirectAction可重定向到其他namspace的action ,这里必须用type="redirectAction"-->
<action name="redirectOtherAction" class="action.TiaoZhuan"  method="redirectOtherAction">
<result name="redirectOtherAction" type="redirectAction">
   <param name="actionName">other_namespace</param>
   <param name="namespace">/lhy</param>
</result>
</action>

<!-- plainText源码显示 -->
<action name="plainText" class="action.TiaoZhuan" method="plainText">
<result name="plainText" type="plainText">
<param name="location">/index1.jsp</param>
<param name="charSet">UTF-8</param>
</result>
</action>
</package>

  <package name="struts2" namespace="/lhy" extends="struts-default" >
 <action  name="other_namespace" class="action.TiaoZhuan"  method="other_namespace">
     <result name="other_namespace">/index1.jsp</result>
  </action>
</package>
</struts>



jsp页面

<body>
    <a href="dispatcher_to_webinf">转发到webinf</a><br/>
    <a href="redirect_to_webinf">重定向到webinf</a><br/>
    <a href="chain">chain链式转发</a><br/>
    <a href="redirectAction">redirectAction重定向到action</a><br/>
     <a href="redirectOtherAction">redirectOtherAction重定向到其他namespace的action</a><br/>
      <a href="plainText">plainText源码</a><br/>
      <a href="lhy/other_namespace">lhy namespace下的action</a><br/>
       <a href="param_redirect?id=123">带参数的重定向</a><br/>
  </body>


java action代码


package action;


import com.opensymphony.xwork2.ActionSupport;


public class TiaoZhuan extends ActionSupport{

private String userName;
private String userName1;
private String id;


public String dispatcher()
{
return "dispatcher";
}

public String redirect()
{
System.out.println("redirect重定向jsp");
return "redirect";
}
public String redirectAction()
{
System.out.println("redirectAction重定向action");
return "redirectAction";
}

public String chain()
{
System.out.println("chain开始链式转发");
userName="lhy";
userName1="wxl";
return "chain";
}


public String chain1()
{
System.out.println("chain转发后的值"+userName+" "+userName1);
return "chain1";
}


public String plainText()
{
System.out.println("plainText源程序");
return "plainText";
}
public String plaintext()
{
System.out.println("源码显示");
return "plaintext";
}

public String redirectOtherAction()
{
System.out.println("开始重定向到其他的的namespace");
return "redirectOtherAction";
}

public String other_namespace()
{
System.out.println("已经重定向到其他的namespace");
return "other_namespace";
}

public String param_redirect()
{
id="456";
System.out.println("带参数的重定向");
return "param_redirect";
}

public String getUserName() {
return userName;
}


public void setUserName(String userName) {
this.userName = userName;
}


public String getUserName1() {
return userName1;
}


public void setUserName1(String userName1) {
this.userName1 = userName1;
}


public String getId() {
return id;
}


public void setId(String id) {
this.id = id;
}



}

这篇关于struts2 result type= redirect redirectAction chain dispatcher等类型的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1140492

相关文章

Python如何查看数据的类型

《Python如何查看数据的类型》:本文主要介绍Python如何查看数据的类型方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录python查看数据的类型1. 使用 type()2. 使用 isinstance()3. 检查对象的 __class__ 属性4.

Python容器类型之列表/字典/元组/集合方式

《Python容器类型之列表/字典/元组/集合方式》:本文主要介绍Python容器类型之列表/字典/元组/集合方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录1. 列表(List) - 有序可变序列1.1 基本特性1.2 核心操作1.3 应用场景2. 字典(D

Python如何在Word中生成多种不同类型的图表

《Python如何在Word中生成多种不同类型的图表》Word文档中插入图表不仅能直观呈现数据,还能提升文档的可读性和专业性,本文将介绍如何使用Python在Word文档中创建和自定义各种图表,需要的... 目录在Word中创建柱形图在Word中创建条形图在Word中创建折线图在Word中创建饼图在Word

SpringBoot接收JSON类型的参数方式

《SpringBoot接收JSON类型的参数方式》:本文主要介绍SpringBoot接收JSON类型的参数方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教... 目录一、jsON二、代码准备三、Apifox操作总结一、JSON在学习前端技术时,我们有讲到过JSON,而在

Rust中的BoxT之堆上的数据与递归类型详解

《Rust中的BoxT之堆上的数据与递归类型详解》本文介绍了Rust中的BoxT类型,包括其在堆与栈之间的内存分配,性能优势,以及如何利用BoxT来实现递归类型和处理大小未知类型,通过BoxT,Rus... 目录1. Box<T> 的基础知识1.1 堆与栈的分工1.2 性能优势2.1 递归类型的问题2.2

Python如何计算两个不同类型列表的相似度

《Python如何计算两个不同类型列表的相似度》在编程中,经常需要比较两个列表的相似度,尤其是当这两个列表包含不同类型的元素时,下面小编就来讲讲如何使用Python计算两个不同类型列表的相似度吧... 目录摘要引言数字类型相似度欧几里得距离曼哈顿距离字符串类型相似度Levenshtein距离Jaccard相

Go语言中三种容器类型的数据结构详解

《Go语言中三种容器类型的数据结构详解》在Go语言中,有三种主要的容器类型用于存储和操作集合数据:本文主要介绍三者的使用与区别,感兴趣的小伙伴可以跟随小编一起学习一下... 目录基本概念1. 数组(Array)2. 切片(Slice)3. 映射(Map)对比总结注意事项基本概念在 Go 语言中,有三种主要

解决Spring运行时报错:Consider defining a bean of type ‘xxx.xxx.xxx.Xxx‘ in your configuration

《解决Spring运行时报错:Considerdefiningabeanoftype‘xxx.xxx.xxx.Xxx‘inyourconfiguration》该文章主要讲述了在使用S... 目录问题分析解决方案总结问题Description:Parameter 0 of constructor in x

Redis的Zset类型及相关命令详细讲解

《Redis的Zset类型及相关命令详细讲解》:本文主要介绍Redis的Zset类型及相关命令的相关资料,有序集合Zset是一种Redis数据结构,它类似于集合Set,但每个元素都有一个关联的分数... 目录Zset简介ZADDZCARDZCOUNTZRANGEZREVRANGEZRANGEBYSCOREZ

IDEA如何将String类型转json格式

《IDEA如何将String类型转json格式》在Java中,字符串字面量中的转义字符会被自动转换,但通过网络获取的字符串可能不会自动转换,为了解决IDEA无法识别JSON字符串的问题,可以在本地对字... 目录问题描述问题原因解决方案总结问题描述最近做项目需要使用Ai生成json,可生成String类型