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中Json和其他类型相互转换的实现示例

《Python中Json和其他类型相互转换的实现示例》本文介绍了在Python中使用json模块实现json数据与dict、object之间的高效转换,包括loads(),load(),dumps()... 项目中经常会用到json格式转为object对象、dict字典格式等。在此做个记录,方便后续用到该方

python中的显式声明类型参数使用方式

《python中的显式声明类型参数使用方式》文章探讨了Python3.10+版本中类型注解的使用,指出FastAPI官方示例强调显式声明参数类型,通过|操作符替代Union/Optional,可提升代... 目录背景python函数显式声明的类型汇总基本类型集合类型Optional and Union(py

MySQL中查询和展示LONGBLOB类型数据的技巧总结

《MySQL中查询和展示LONGBLOB类型数据的技巧总结》在MySQL中LONGBLOB是一种二进制大对象(BLOB)数据类型,用于存储大量的二进制数据,:本文主要介绍MySQL中查询和展示LO... 目录前言1. 查询 LONGBLOB 数据的大小2. 查询并展示 LONGBLOB 数据2.1 转换为十

MyBatis的xml中字符串类型判空与非字符串类型判空处理方式(最新整理)

《MyBatis的xml中字符串类型判空与非字符串类型判空处理方式(最新整理)》本文给大家介绍MyBatis的xml中字符串类型判空与非字符串类型判空处理方式,本文给大家介绍的非常详细,对大家的学习或... 目录完整 Hutool 写法版本对比优化为什么status变成Long?为什么 price 没事?怎

C#之枚举类型与随机数详解

《C#之枚举类型与随机数详解》文章讲解了枚举类型的定义与使用方法,包括在main外部声明枚举,用于表示游戏状态和周几状态,枚举值默认从0开始递增,也可手动设置初始值以生成随机数... 目录枚举类型1.定义枚举类型(main外)2.使用生成随机数总结枚举类型1.定义枚举类型(main外)enum 类型名字

Python lambda函数(匿名函数)、参数类型与递归全解析

《Pythonlambda函数(匿名函数)、参数类型与递归全解析》本文详解Python中lambda匿名函数、灵活参数类型和递归函数三大进阶特性,分别介绍其定义、应用场景及注意事项,助力编写简洁高效... 目录一、lambda 匿名函数:简洁的单行函数1. lambda 的定义与基本用法2. lambda

C语言自定义类型之联合和枚举解读

《C语言自定义类型之联合和枚举解读》联合体共享内存,大小由最大成员决定,遵循对齐规则;枚举类型列举可能值,提升可读性和类型安全性,两者在C语言中用于优化内存和程序效率... 目录一、联合体1.1 联合体类型的声明1.2 联合体的特点1.2.1 特点11.2.2 特点21.2.3 特点31.3 联合体的大小1

MySQL 索引简介及常见的索引类型有哪些

《MySQL索引简介及常见的索引类型有哪些》MySQL索引是加速数据检索的特殊结构,用于存储列值与位置信息,常见的索引类型包括:主键索引、唯一索引、普通索引、复合索引、全文索引和空间索引等,本文介绍... 目录什么是 mysql 的索引?常见的索引类型有哪些?总结性回答详细解释1. MySQL 索引的概念2

Java获取当前时间String类型和Date类型方式

《Java获取当前时间String类型和Date类型方式》:本文主要介绍Java获取当前时间String类型和Date类型方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,... 目录Java获取当前时间String和Date类型String类型和Date类型输出结果总结Java获取

SpringBoot改造MCP服务器的详细说明(StreamableHTTP 类型)

《SpringBoot改造MCP服务器的详细说明(StreamableHTTP类型)》本文介绍了SpringBoot如何实现MCPStreamableHTTP服务器,并且使用CherryStudio... 目录SpringBoot改造MCP服务器(StreamableHTTP)1 项目说明2 使用说明2.1