• 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中找到:

     

  • 相关阅读:
    关于js拖拽功能,拖拽元素的position:fixed;left:0;right:0;样式引起左右拖动元素会出现落后鼠标移动距离的问题
    关于js无法设置input的value的问题
    虚拟机linux 挂载windows共享目录 给linux的nginx服务器使用
    linux Centos7 安装Samba服务
    CentOS 7.1使用yum安装MySql5.6.24
    CentOS7下开启端口
    IE浏览器对虚拟主机配置域名的问题
    关于CI框架加入sphinx官方API接口文件的时候,需要注意的问题
    -webkit-box-flex: 1;属性和 float 属性冲突造成元素看不见的BUG
    第二十四天
  • 原文地址:https://www.cnblogs.com/hanyuan/p/2536738.html
Copyright © 2020-2023  润新知