Struts2中Action接收参数的方法

 

Struts2中Action接收参数的方法主要有以下三种:
1.使用Action的属性接收参数:
    a.定义:在Action类中定义属性,创建get和set方法;
    b.接收:通过属性接收参数,如:userName;
    c.发送:使用属性名传递参数,如:user1!add?userName=Magci;
2.使用DomainModel接收参数:
    a.定义:定义Model类,在Action中定义Model类的对象(不需要new),创建该对象的get和set方法;
    b.接收:通过对象的属性接收参数,如:user.getUserName();
    c.发送:使用对象的属性传递参数,如:user2!add?user.userName=MGC;
3.使用ModelDriven接收参数:
    a.定义:Action实现ModelDriven泛型接口,定义Model类的对象(必须new),通过getModel方法返回该对象;
    b.接收:通过对象的属性接收参数,如:user.getUserName();
    c.发送:直接使用属性名传递参数,如:user2!add?userName=MGC;

实例:

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <welcome-file-list>
    <welcome-file>hello.jsp</welcome-file>
  </welcome-file-list>
  <filter>
    <filter-name>struts2</filter-name>
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>struts2</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
</web-app>

 

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">

<struts>
<!--
<constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="false" />

<include file="example.xml"/>



<package name="default" namespace="/" extends="struts-default">
<default-action-ref name="index" />
<action name="index">
<result type="redirectAction">
<param name="actionName">HelloWorld</param>
<param name="namespace">/example</param>
</result>
</action>
</package>
-->

<!-- Add packages here -->
<constant name="struts.devMode" value="true" />
<package name="user" namespace="/" extends="struts-default">
<action name="user*" class="cn.edu.ahau.mgc.struts2.action.UserAction{1}">
<result>/addSuccess.jsp</result>
</action>
</package>
</struts>
 

User.java:

package cn.edu.ahau.mgc.struts2.mode;

public class User {

    private String userName;
    private String password;
    
    public String getUserName() {
        return this.userName;
    }
    
    public void setUserName(String userName) {
        this.userName = userName;
    }
    
    public String getPassword() {
        return this.password;
    }
    
    public void setPassword(String password) {
        this.password = password;
    }
}

 

UserAction1.java:

 写道
package cn.edu.ahau.mgc.struts2.action;

import com.opensymphony.xwork2.ActionSupport;

public class UserAction1 extends ActionSupport {

private String userName;
private String password;

public String add() {
System.out.println("userName: " + userName);
System.out.println("password: " + password);
return SUCCESS;
}

public String getUserName() {
return this.userName;
}

public void setUserName(String userName) {
this.userName = userName;
}

public String getPassword() {
return this.password;
}

public void setPassword(String password) {
this.password = password;
}
}

 

UserAction2.java:

 

 写道
package cn.edu.ahau.mgc.struts2.action;

import com.opensymphony.xwork2.ActionSupport;

import cn.edu.ahau.mgc.struts2.mode.User;

public class UserAction2 extends ActionSupport {

private User user;

public String add() {
System.out.println("userName: " + user.getUserName());
System.out.println("password: " + user.getPassword());
return SUCCESS;
}

public User getUser() {
return this.user;
}

public void setUser(User user) {
this.user = user;
}

}

 

UserAction3.java:

 

 写道
package cn.edu.ahau.mgc.struts2.action;

import cn.edu.ahau.mgc.struts2.mode.User;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class UserAction3 extends ActionSupport implements ModelDriven<User> {

private User user = new User();

public String add() {
System.out.println("userName: " + user.getUserName());
System.out.print("password: " + user.getPassword());
return SUCCESS;
}

public User getModel() {
return this.user;
}

}

 

index.jsp:

 写道
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>Param</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>

<body>
<a href="user1!add?userName=Magci&password=123456">user1!add?userName=Magci&password=123456</a>
<br />
<br />

<a href="user2!add?user.userName=MGC&user.password=abc">user2!add?user.userName=MGC&user.password=abc</a>
<br />
<br />

<a href="user3!add?userName=MaGC&password=000000">user3!add?userName=MaGC&password=000000</a>
</body>
</html>
 addSuccess.jsp:

<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>AddSuccess</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
  </head>
  
  <body>
    User Add Success! <br>
  </body>
</html>
 
OFDM(正交频分复用)是一种高效的多载波通信技术,它将高速数据流拆分为多个低速子流,并通过多个并行的低带宽子载波传输。这种技术具有高频谱效率、强抗多径衰落能力和灵活的带宽分配优势。 OFDM系统利用大量正交子载波传输数据,子载波间的正交性可有效避免码间干扰(ISI)。其数学表达为多个离散子载波信号的线性组合,调制和解调过程通过FFT(快速傅立叶变换)和IFFT(逆快速傅立叶变换)实现。其关键流程包括:数据符号映射到子载波、IFFT转换为时域信号、添加循环前缀以减少ISI、信道传输、接收端FFT恢复子载波数据和解调原始数据。 Matlab是一种广泛应用于科研、工程和数据分析的高级编程语言和交互式环境。在OFDM系统设计中,首先需掌握Matlab基础,包括编程语法、函数库和工具箱。接着,根据OFDM原理构建系统模型,实现IFFT/FFT变换、循环前缀处理和信道建模等关键算法,并通过改变参数(如信噪比、调制方式)评估系统性能。最后,利用Matlab的绘图功能展示仿真结果,如误码率(BER)曲线等。 无线通信中主要考虑加性高斯白噪声(AWGN),其在频带上均匀分布且统计独立。通过仿真OFDM系统,可在不同信噪比下测量并绘制BER曲线。分析重点包括:不同调制方式(如BPSK、QPSK)对BER的影响、循环前缀长度选择对性能的影响以及信道估计误差对BER的影响。 OFDM技术广泛应用于多个领域,如数字音频广播(DAB)、地面数字电视广播(DVB-T)、无线局域网(WLAN)以及4G/LTE和5G移动通信,是这些通信标准中的核心技术之一。 深入研究基于Matlab的OFDM系统设计与仿真,有助于加深对OFDM技术的理解,并提升解决实际通信问题的能力。仿真得到的关键性能指标(如BER曲线)对评估系统可靠性至关重要。未来可进一步探索复杂信道条件下的OFDM性能及系统优化,以适应不同应用场景
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值