1.采用基本类型接收请求参数(get/post)
在Action类中定义与请求参数同名的属性,struts2便能自动接收请求参数并赋予给同名属性
请求路径: http://localhost:8080/test/view.action?id=78
public class ProductAction{
private Integer id;
//构建GET SET 方法
public void setId(Integer id){
this.id = id ;
}
public Integer getId(){
return id;
}
//struts2通过反射技术调用与请求参数同名的属性的setter方法来获取请求参数值
}
2.采用复合类型接收请求参数
请求路径: http://localhost:8080/test/view.action?product.id=78
public class ProductAction{
private Product product;
//构建GET SET 方法
public void setProduct (Product product){
this.product = product ;
}
public Product getProduct (){
return product ;
}
//struts2首先通过反射技术调用Product的默认构造器创建product对象,然后再通过反射技术调用product中与请求参数同名的属性的setter方法来获取请求参数
}
本文介绍了Struts2框架中两种接收HTTP请求参数的方法:一是使用基本类型接收简单参数;二是利用复合类型处理复杂的参数结构。通过实例展示了如何定义Action类以实现参数的自动填充。
845

被折叠的 条评论
为什么被折叠?



