一、访问servletAPI方式
Action类中
ActionContext context = ActionContext.getContext();
String parameter = (String)context.get("cust_name"); //三个域中查找
Map<String, Object> application = context.getApplication(); //application域
Map<String, Object> session = context.getSession();//session域
Map<String, Object> parameters = context.getParameters();//request域
二、结果跳转方式
type属性 | 说明 |
---|---|
dispatcher | 转发 |
redirect | 重定向 |
chain | 跳转到Action后仍接受上一页面的值,比如 request |
redirectAction | 重定向到Action丢失页面传递的信息 |
三、数据的封装
1.属性驱动
页面提供表达式方式
Action类中
private Customer customer;
//必须实现对象的get方法
public Customer getCustomer() {
return customer;
}
jsp页面中
<form action="${pageContext.request.contextPath }/customer_add">
<input type="text" name="customer.name">
2.模型驱动
jsp和以前的一样 不用改动
Action类的书写
实现ModelDriven 实现接口 构建对象
public class DemoAction extends ActionSupport implements ModelDriven<Customer>{
//手动构建对象
private Customer customer=new Customer();
@Override
public Customer getModel() {
// TODO Auto-generated method stub
return customer;
}
}
三、封装到集合
1.封装到List集合
编写页面
<form action="${pageContext.request.contextPath }/customer_add">
<input type="text" name="list[0].name">
<input type="text" name="list[0].age">
<input type="text" name="list[0].birthday">
<input type="text" name="list[1].name">
<input type="text" name="list[1].age">
<input type="text" name="list[1].birthday">
<input type="submit" value="提交">
</form>
Action类的编写
public class DemoAction extends ActionSupport {
private List<Customer> list;
public List<Customer> getList() {
return list;
}
public void setList(List<Customer> list) {
this.list = list;
}
}
利用下标来区分….
2.封装到Map集合
页面编写:
<form action="${pageContext.request.contextPath }/customer_add">
<input type="text" name="map['one'].name">
<input type="text" name="map['one'].age">
<input type="text" name="map['one'].birthday">
<input type="text" name="map['two'].name">
<input type="text" name="map['two'].age">
<input type="text" name="map['two'].birthday">
<input type="submit" value="提交">
</form>
编写Action:
public class DemoAction extends ActionSupport {
private Map<String,Customer> map;
public Map<String, Customer> getMap() {
return map;
}
public void setMap(Map<String, Customer> map) {
this.map = map;
}
}