一、采用基本类型接收请求参数(get/post)。post
在Action类中定义与请求参数同名的属性,struts2便能自动接受请求参数并赋予给同名属性。this
请求路径:http://localhost:8080/test/view.ation?id=78对象
public class ProductActionget
{io
private integerId;class
public viod setld(integerId)test
{//struts2经过反射技术调用与请求参数同名的属性的selter方法来获取请求参数值struts2
this.id=id;请求
}反射
public integer gerId()
{
return id;
}
}
二、采用复合类型接收请求参数。
请求路径:http://localhost:8080/test/view.ation?id=78
public class ProductAction
{
private Product product;
public void setProduct(Product product)
{
this.product=product;
}
public Product getProduct()
{
return product;
}
}
Struts2首先经过反射技术调用Product的默认构造器建立product对象而后再经过反射技术调用product中与请求参数同名的属性的selter方法来获取请求参数值。