struts2 action重定向
struts2的结果类型:
<action name="loginAction" class="com.itheima.action.LoginAction">
<result name="success" <strong><span style="color:#FF6666;">type="chain"</span></strong>>
<param name="actionName">successAction</param>
<param name="name">${name}</param>
</result>
</action>
struts2中的结果类型有下面几种:
<result-types>
<result-type name="chain" class="com.opensymphony.xwork2.ActionChainResult"/>
<result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"/>
<result-type name="freemarker" class="org.apache.struts2.views.freemarker.FreemarkerResult"/>
<result-type name="httpheader" class="org.apache.struts2.dispatcher.HttpHeaderResult"/>
<result-type name="redirect" class="org.apache.struts2.dispatcher.ServletRedirectResult"/>
<result-type name="redirectAction" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/>
<result-type name="stream" class="org.apache.struts2.dispatcher.StreamResult"/>
<result-type name="velocity" class="org.apache.struts2.dispatcher.VelocityResult"/>
<result-type name="xslt" class="org.apache.struts2.views.xslt.XSLTResult"/>
<result-type name="plainText" class="org.apache.struts2.dispatcher.PlainTextResult" />
<result-type name="postback" class="org.apache.struts2.dispatcher.PostbackResult" />
</result-types>
重要的有几下几种:
dispatcher —— 请求转发到一个页面 (默认),不能够用这样的方式转发到一个action
chain —— 一个action请求转发至还有一个 action
redirect —— 响应重定向到一个页面,也能够实现响应重定向到action
redirectAction       —— 一个action响应重定向至还有一个
 action
stream —— 文件下载
注意:假设结果类型改成 type = “chain” ,则加了那些携带的參数都不会起到作用,由于chain 是请求转发,还在一次请求内,本来就携带了參数,不须要再去声明,也不能够加入别的參数,不会起到作用,由于一開始表单提交信息后,该次请求的信息以固定。
响应重定向可防止表单反复提交
一般action重定向到jsp,可是有时会重定向到还有一个action
首先看下LoginAction.java
package com.itheima.action;
public class LoginAction {
	private String name;
	public String getName() {
		return name;
	}
	public String execute() {
		//名字固化,所以不须要setXXX()方法
		name="lcl";
		return "success";
	}
}
SuccessAction.java
package com.itheima.action;
public class SuccessAction {
	private String name;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String execute() {
		return "success";
	}
}
假设重定向时传递參数,有下面几种方式:
<action name="loginAction" class="com.itheima.action.LoginAction">
<result type="redirect">successAction?name=${name}</result>
</action> <action name="successAction" class="com.itheima.action.SuccessAction">
<result type="redirect">/login.jsp?name=${name}</result>
</action>
<action name="loginAction" class="com.itheima.action.LoginAction">
<result type="redirectAction">successAction?name=${name}</result>
</action> <action name="successAction" class="com.itheima.action.SuccessAction">
<result type="redirect">/login.jsp?name=${name}</result>
</action>
<action name="loginAction" class="com.itheima.action.LoginAction">
<result type="redirectAction">
<param name="actionName">successAction</param>
<param name="name">${name}</param>
</result>
</action> <action name="successAction" class="com.itheima.action.SuccessAction">
<result type="redirect">/login.jsp?name=${name}</result>
</action>
可是以下这样的配置不行:
<action name="loginAction" class="com.itheima.action.LoginAction">
<result type="redirect">
<param name="actionName">successAction</param>
<param name="name">${name}</param>
</result>
</action> <action name="successAction" class="com.itheima.action.SuccessAction">
<result type="redirect">/login.jsp?name=${name}</result>
</action>
struts2 action重定向的更多相关文章
- struts2 action重定向action中文乱码处理
		
比如:Action方法productCategorySave()变量message,传递给Action方法productCategoryAdd(),当变量message为中文变量时,要进行编码设置,不 ...
 - struts2 action 页面跳转
		
struts2 action 页面跳转 标签: actionstruts2redirect 2013-11-06 16:22 20148人阅读 评论(0) 收藏 举报 (1)type="di ...
 - struts2 action result type类型
		
struts2 action result type类型 1.chain:用来处理Action链,被跳转的action中仍能获取上个页面的值,如request信息. com.opensymphony. ...
 - struts2 action配置时 method 省略不写 默认执行方法是父类ActionSuppot中的execute()方法
		
struts2 action配置时 method 省略不写 默认执行方法是父类ActionSuppot中的execute()方法
 - Java Hour 32 Weather ( 5 ) struts2 – Action class
		
有句名言,叫做10000小时成为某一个领域的专家.姑且不辩论这句话是否正确,让我们到达10000小时的时候再回头来看吧. Hour 32 Struts2 Action 1 将action 映射到 ac ...
 - Struts2 Action接收表单参数
		
struts2 Action获取表单传值 1.通过属性驱动式 JSP: <form action="sys/login.action" method ...
 - struts2 action通配符
		
首先,看一个struts2的配置文件: <package name="actions" extends="struts-default" namespac ...
 - Struts2中重定向和请求转发配置
		
struts2中默认跳转为dispatcher请求转发 只能往jsp转发,跳转action报404 重定向 设置为redirect ,可以是jsp也可以是action <!--同一个包下的act ...
 - ASP.Net MVC Action重定向跳出Controller和Area
		
1.重定向方法简介 [HttpPost] public ActionResult StudentList( string StudName, string studName, DateTime Bir ...
 
随机推荐
- 89c52串口发送接收小示例
			
//串口发送 void sendChar(char *p)//调用前关中断,调用完成后关中断 { while(*p != '\0') { SBUF = *P while(!TI); TI = 0; p ...
 - js获取某个标签中的信息
			
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http ...
 - 传输中文乱码js解决方法
			
encodeURI要编码两次 var a="我的"; //编译两次 //window.location.href = "http://127.0.0.1:8080/kab ...
 - System.Speech.Synthesis 添加暂停、继续功能
			
为了方便调用暂停.继续的方法.要将speech的功能写成一个类.直接附上代码: using System; using System.Collections.Generic; using System ...
 - (原)Eclipse的java中文件读写
			
1 在<uses-sdk…/>下面添加permission <uses-sdk android:minSdkVersion="16" android:target ...
 - 创建ListView的基本步骤
			
参考<疯狂android讲义>第2.5节P94 1.创建一个或者多个ListView <LinearLayout xmlns:android="http://schemas ...
 - IE 与 FireFox 的 event 详解 (转)
			
原文链接 FF的FIREBUG,不仅能测试JS还能检查CSS错误,是一般常用的. 但它主要检查FF方面的错误,对IE就无能为力了. 要测试IE,就用ieTester,它可以测试IE几乎所有版本(1.0 ...
 - [ZooKeeper研究]二  ZooKeeper协议介绍
			
前面介绍了ZooKeeper的基本知识,这一节我们介绍一下ZooKeeper使用的协议.只有了解了ZooKeeper的协议,才能更好得理解ZooKeeper源代码的实现.ZooKeeper使用的是Za ...
 - debian修改系统语言为英文
			
原文地址:http://www.chenyudong.com/archives/debian-change-locale-language.html 修改/etc/default/locale 文件里 ...
 - linux io优化
			
场景:xml文件解析入库:并备份 问题:磁盘io异常,经常100%busy: linux io优化方法: 1.修改磁盘挂着参数,修改为writeback模式:对于文件读取频繁的可以设置noatime: ...