一: struts-config.xml 配置
二: 输入页面�0�2add_traffic_policy.jsp
�0�2
<%@ page language="java" import="java.util.*"
contentType="text/html; charset=utf-8" isELIgnored="false"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic"%>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
添加流量监控策略 rel="stylesheet" type="text/css" id="cssStyle" />
cellspacing="0">
background="<%=request.getContextPath()%>/images/main_02.gif"> width="9" height="33" /> |
background="<%=request.getContextPath()%>/images/main_02.gif"> width="18" height="17" /> |
background="<%=request.getContextPath()%>/images/main_02.gif" class="text10"> 添加流量监控策略 |
�0�2
�0�2
三: TrafficForm的关键代码
public class TrafficForm extends BaseActionForm implements Serializable {
private static final long serialVersionUID = 454397279205151336L;
private List traffics = new AutoArrayList(Traffic.class);
public List getTraffics() {
return traffics;
}
public void setTraffics(List traffics) {
this.traffics.clear();
this.traffics.addAll(traffics);
}
}
�0�2
四.bean,提问页面省略了get set方法
public class Traffic extends BaseActionForm implements Serializable {
private static final long serialVersionUID = 454397279205151336L;
/**
* Fields
*/
private Integer policyId;
private Integer checkDay;
private Integer warnPercent;
private String warnContent;
/** default constructor */
public Traffic() {
}
/** full constructor */
public Traffic(Integer policyId, Integer checkDay, Integer warnPercent, String warnContent) {
super();
this.policyId = policyId;
this.checkDay = checkDay;
this.warnPercent = warnPercent;
this.warnContent = warnContent;
}
�0�2 �0�2 �0�2 �0�2
五.�0�2自定义的 AutoArrayList
public class AutoArrayList extends ArrayList implements Serializable {
private static final long serialVersionUID = 1L;
private Class itemClass;
public AutoArrayList(Class itemClass){
this.itemClass = itemClass;
}
public Object get(int index){
try {
while(index >= size()){
add(itemClass.newInstance());
}
} catch (Exception e) {
e.printStackTrace();
}
return super.get(index);
}
}
�0�2
六.AddTraPolicyAction
TrafficForm trafficForm = (TrafficForm)form;
List traffics = trafficForm.getTraffics();
System.out.println("traffics.size():"+traffics.size());
for (int i = 0; i < traffics.size(); i++) {
Traffic traffic = (Traffic) traffics.get(i);
System.out.println("Traffic["+i+"]CheckDay:"+traffic.getcheckDay()+" WarnPercent:"+traffic.getWarnPercent()+" WarnContent:"+traffic.getWarnContent());
}
// Integer checkDay = trafficForm.getcheckDay();
// Integer warnPercent = trafficForm.getWarnPercent();
// String warnContent = trafficForm.getWarnContent();
// System.out.println("checkDay:"+checkDay);
// System.out.println("warnPercent:"+warnPercent);
// System.out.println("warnContent:"+warnContent);
//
// String[] days = request.getParameterValues("day");
// String[] pers = request.getParameterValues("per");
// String[] contents = request.getParameterValues("content");
// System.out.println("测试day数组元素个数"+days.length);
// System.out.println("测试pers数组元素个数"+pers.length);
// System.out.println("测试contents数组元素个数"+contents.length);
// while(request.getParameterNames().hasMoreElements()){
// String day=(String)request.getParameterNames().nextElement();
// String value=request.getParameter(day);
// System.out.println("测试name:"+day+",它的值是:"+value);
// }
在action中测试,试过traffics的size总是1,总是只能获取表格中的第一行数据。也试过request.getParameterValues依然取不到其他行的数据,求解哪里有问题呢?附上我参考的页面
http://tech.ddvip.com/2008-12/122881555798671_2.html