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;
}

}

时间: 2024-08-31 00:51:26

struts2 result type= redirect redirectAction chain dispatcher等类型的相关文章

struts2 action中result type=&amp;amp;quot;chain&amp;amp;quot;跳转问题

问题描述 action配置如下:<package name="richang" namespace="/richang" extends="office"> <action name="meeting" class="com.struts.action.MeetingAction"> <result name="list">/RiChang/meeti

Struts2 Result 参数详解_java

一个提交到服务器的处理通常可以分为两个阶段,第一个阶段查询服务器状态(查询或者更新数据库),第二个阶段选择一个合适的结果页面其返回给用户(这里要讲的Result的内容). Struts2提供了对不同种类返回结果的支持,常见的有JSP,FreeMarker,Velocity等. Struts2支持的不同类型的返回结果为: 名字 说明 Chain Result 用来处理Action链 Dispatcher Result 用来转向页面,通常处理JSP FreeMarker Result 处理FreeM

Struts2 Result 返回JSON对象详解_java

如果是作为客户端的HTTP+JSON接口工程,没有JSP等view视图的情况下,使用Jersery框架开发绝对是第一选择.而在基于Spring3 MVC的架构下,对HTTP+JSON的返回类型也有很好的支持.但是,在开发工作中,对功能的升级是基于既定架构是很常见的情况.本人碰到需要用开发基于Struts2的HTTP+JSON返回类型接口就是基于既定框架结构下进行的. Struts2返回JSON有两种方式:1.使用Servlet的输出流写入JSON字符串:2.使用Struts2对JSON的扩展.

no result type defined for type &#039;dispatch&#039;mapped

自己打算弄个webwork测试问题时候,遇到个脑瘫的问题,配了xwork之后,死活找不到action,报There is no result type defined for type 'dispatcher' mapped with name 'success' 的错误,找了半天,发现需要在xwork配置文件中加入: <include file="webwork-default.xml"/> <package name="helloWorld"

struts2上传下载,下载非txt类型文档后台报错,但文件成功下载了

问题描述 struts2上传下载,下载非txt类型文档后台报错,但文件成功下载了 下载非txt类型文档时后台报了个异常:(下载txt不报异常) java.lang.IllegalStateException: Cannot call sendError() after the response has been committed at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:451)

ist iew-跪求:Android在listview中item没有type,如何控制展示不同类型的图片

问题描述 跪求:Android在listview中item没有type,如何控制展示不同类型的图片 在一个界面中,一个接口有很多的图片,一张大图,下面4张小图,在接着两个大图,后面两张小图,就这个模式展示,想不到用什么方法. 解决方案 没理解你这是什么样的布局,想要展示成什么样. 解决方案二: 这个不是在布局文件里布局好的,然后在代码里设置好,最后填充进listview的吗? 如果回答对您有帮助,请采纳 解决方案三: 确实没有理解到你想要做成什么效果 解决方案四: 如果没理解错的话你可以用瀑布流

struts2 validation.xml验证失败及result type=chain

问题描述 小弟最近在做一个简单的struts2的小东西,遇到了麻烦,代码如下struts2配置文件<actionname="manageKind"class="action.ManageKindAction"><result>/WEB-INF/jsp/manageKind.jsp</result></action><actionname="addKind"class="action.

struts validator后type=&amp;amp;quot;chain&amp;amp;quot; unknown acton问题求帮忙!

问题描述 struts validator后type="chain" unknown acton问题求帮忙! 在struts.xml中配置了,saveUUser的input使用chain方式跳转到edit这个action里面, 然而还配置了saveUUser的validator的xml进行验证字段,字段验证格式错误后,跳转则显示 java.lang.RuntimeException: Invalid action class configuration that references

为什么AWS CDN的统计报告里,&amp;amp;quot;Percentage of Viewer Requests by Result Type&amp;amp;quot;,总和并不是100%啊,在

问题描述 为什么AWSCDN的统计报告里,"PercentageofViewerRequestsbyResultType",总和并不是100%啊,在85%~95%之间波动? 解决方案 解决方案二:thechartdoesn'tincluderefreshhit.refreshhit是在cdn节点找到了这个文件,但是文件失效,所以需要再次回源获取文件.