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

相关文章

HTML5的input标签的`type`属性值详解和代码示例

《HTML5的input标签的`type`属性值详解和代码示例》HTML5的`input`标签提供了多种`type`属性值,用于创建不同类型的输入控件,满足用户输入的多样化需求,从文本输入、密码输入、... 目录一、引言二、文本类输入类型2.1 text2.2 password2.3 textarea(严格

MyBatis中的两种参数传递类型详解(示例代码)

《MyBatis中的两种参数传递类型详解(示例代码)》文章介绍了MyBatis中传递多个参数的两种方式,使用Map和使用@Param注解或封装POJO,Map方式适用于动态、不固定的参数,但可读性和安... 目录✅ android方式一:使用Map<String, Object>✅ 方式二:使用@Param

C# WebAPI的几种返回类型方式

《C#WebAPI的几种返回类型方式》本文主要介绍了C#WebAPI的几种返回类型方式,包括直接返回指定类型、返回IActionResult实例和返回ActionResult,文中通过示例代码介绍的... 目录创建 Controller 和 Model 类在 Action 中返回 指定类型在 Action

python中的鸭子类型详解

《python中的鸭子类型详解》鸭子类型是Python动态类型系统的灵魂,它通过强调“行为”而非“类型”,赋予了代码极大的灵活性和表现力,本文给大家详细介绍python中的鸭子类型,感兴趣的朋友一起看... 目录1. 核心思想:什么是鸭子类型?2. 与“传统”静态类型语言的对比3. python 中无处不在

Java枚举类型深度详解

《Java枚举类型深度详解》Java的枚举类型(enum)是一种强大的工具,它不仅可以让你的代码更简洁、可读,而且通过类型安全、常量集合、方法重写和接口实现等特性,使得枚举在很多场景下都非常有用,本文... 目录前言1. enum关键字的使用:定义枚举类型什么是枚举类型?如何定义枚举类型?使用枚举类型:2.

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 类型名字