Struts2中请求参数以action属性的方式被初始化赋值。所以在action类中的属性同页面提交的参数存在一一对应的关系。action中属性实现的get(),set()方法提供了Struts2框架注入值和在返回页面中获取值的渠道。
以下为参数接收的方式:
1、基本类型参数接收请求参数(get/post)
请求路径:http://localhost/test/add.action?id=100
.......
private Long id;
public void setId(Long id) { //struts2使用反射技术调用与请求参数同名的属性的setter方法来获取请求参数值
this.id = id;
}
public Long getId() {
return id;
}
......
2、复合类型接收请求参数
请求路径:http://localhost/test/add.action?product.id=100
Action类代码片段
......
private Product prod;
public void setProd(Product prod) { this.prod= prod;
}
public Long getProd() {
return prod;
}
....
Product 封装类
public class Product(){
private Long id;
public void setId(Long id) {
this.id = id;
}
public Long getId() {
return id;
}
}
struts2首先通过反射机制调用Product的构造器创建prod对象,然后再通过反射技术调用prod中与请求参数同名的属性的setter方法获取请求参数。
以上两种参数页面返回值引用方式如下:
<body>
${id} <br> //基本参数引用
${prod.id} <br> //复合类型引用
</body>
</html>
分享到:
相关推荐
struts2-core-2.0.1.jar, struts2-core-2.0.11.1.jar, struts2-core-2.0.11.2.jar, struts2-core-2.0.11.jar, struts2-core-2.0.12.jar, struts2-core-2.0.14.jar, struts2-core-2.0.5.jar, struts2-core-2.0.6.jar,...
Struts2配置文件详解--精品版这个很好很强大
struts2-spring-plugin-2.3.15.2.jar ; struts2-json-plugin-2.3.16.3.jarstruts2-spring-plugin-2.3.15.2.jar ; struts2-json-plugin-2.3.16.3.jar
包含struts2-core-2.5.10.1.jar,struts2-jfreechart-plugin-2.5.10.1.jar,struts2-json-plugin-2.5.10.1.jar,struts2-junit-plugin-2.5.10.1.jar,struts2-bean-validation-plugin-2.5.10.1.jar,struts2-cdi-...
最新struts2-struts1-plugin-2.1.8.1.jar
赠送jar包:struts2-json-plugin-2.3.24.jar; 赠送原API文档:struts2-json-plugin-2.3.24-javadoc.jar; 赠送源代码:struts2-json-plugin-2.3.24-sources.jar; 赠送Maven依赖信息文件:struts2-json-plugin-...
struts2-convention-plugin-2.3.32
struts2-config-browser-plugin-2.3.24.jar, struts2-core-2.3.24.jar, struts2-jasperreports-plugin-2.3.24.jar, struts2-jfreechart-plugin-2.3.24.jar, struts2-pell-multipart-plugin-2.3.24.jar, struts2-...
struts2-ssl-plugin-1.2.1.jar
struts2 最新漏洞 S2-016、S2-017修补方案 .docx
struts2-dojo-plugin-2.3.4 jar 日期控件的jar包 需要的自行下载
struts-config.xml struts标准配置文件 struts-config
struts-spring-other-lib 等jar包struts-spring-other-lib 等jar包struts-spring-other-lib 等jar包struts-spring-other-lib 等jar包struts-spring-other-lib 等jar包struts-spring-other-lib 等jar包struts-spring-...
struts2-dojo-plugin-2.2.1.jar, 直接导入到Struts2项目里即可,注意版本。
struts2-convention-plugin-2.3.24.1
struts2-convention-plugin-2.3.15.1.jar
Struts2应用开发详解]_001.Struts2.2概述与MVC模式深度剖析
struts2-struts1-plugin-2.1.6.jar
struts2-jquery-plugin-3.1.0.jar
JavaEE源代码 struts2-spring-plugin-2.0.11JavaEE源代码 struts2-spring-plugin-2.0.11JavaEE源代码 struts2-spring-plugin-2.0.11JavaEE源代码 struts2-spring-plugin-2.0.11JavaEE源代码 struts2-spring-plugin-...