struts2_Action之间的重定向传参

struts.xml:

复制代码
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <!DOCTYPE struts PUBLIC
 3     "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
 4     "http://struts.apache.org/dtds/struts-2.3.dtd">
 5 
 6 <struts>
 7     <package name="struts" extends="struts-default">
 8         <action name="loginvalidate" class="com.sunflower.action.LoginAction">
 9             <result name="success">/welcome.jsp</result>
10             <!-- 如果输入信息的校验出错,则转回index.jsp -->
11             <result name="input">/index.jsp</result>
12         </action>
13 
14         <action name="action1" class="com.sunflower.action.Action1">
15             <result name="success" type="redirectAction">
16                 <param name="actionName">action2</param>
17                 <param name="username">${username}</param>
18                 <param name="password">${password}</param>
19             </result>
20         </action>
21 
22         <action name="action2" class="com.sunflower.action.Action2">
23             <result name="success">action2.jsp</result>
24         </action>
25     </package>
26 </struts>
复制代码

 

 

action1.jsp:

复制代码
 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5     <head>
 6         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7         <title>信息输入</title>
 8     </head>
 9     <body>
10         <form action="action1" method="post">
11             姓名:<input type="text" name="username"><br>
12             密码:<input type="password" name="password"><br>
13             <input type="submit" value="提交">
14         </form>
15     </body>
16 </html>
复制代码

 

 

action2.jsp:

复制代码
 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <%@ taglib prefix="s" uri="/struts-tags"%>
 4 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 5 <html>
 6     <head>
 7         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 8         <title>显示信息</title>
 9     </head>
10     <body>
11         姓名:<s:property value="username"/>&nbsp;
12         密码:<s:property value="password"/>
13     </body>
14 </html>
复制代码

 

 

Action1.java:

复制代码
 1 package com.sunflower.action;
 2 
 3 import com.opensymphony.xwork2.ActionSupport;
 4 
 5 public class Action1 extends ActionSupport {
 6     private String username;
 7     private String password;
 8 
 9     public String getUsername() {
10         return username;
11     }
12 
13     public void setUsername(String username) {
14         this.username = username;
15     }
16 
17     public String getPassword() {
18         return password;
19     }
20 
21     public void setPassword(String password) {
22         this.password = password;
23     }
24 
25     public String execute() throws Exception {
26         return SUCCESS;
27     }
28 }
复制代码

 

 

Action2.java:

复制代码
 1 package com.sunflower.action;
 2 
 3 import com.opensymphony.xwork2.ActionSupport;
 4 
 5 public class Action2 extends ActionSupport {
 6     private String username;
 7     private String password;
 8 
 9     public String getUsername() {
10         return username;
11     }
12 
13     public void setUsername(String username) {
14         this.username = username;
15     }
16 
17     public String getPassword() {
18         return password;
19     }
20 
21     public void setPassword(String password) {
22         this.password = password;
23     }
24 
25     public String execute() throws Exception {
26         return SUCCESS;
27     }
28 }
复制代码

 

 

关键是在sruts.xml中配置一下,如下:

 

 

 

result-type属性可以在struts-default.xml中找到:

文章来自:http://www.cnblogs.com/hanyuan/archive/2012/06/05/2536738.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值