javax.servlet.ServletException: BeanUtils.populate
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1254)
org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:821)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:254)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
com.zgsx.struts.tool.FilterEncoding.doFilter(FilterEncoding.java:50)
root cause
java.lang.IndexOutOfBoundsException: Index: 1, Size: 0
java.util.ArrayList.RangeCheck(ArrayList.java:547)
java.util.ArrayList.get(ArrayList.java:322)
com.zgsx.struts.tool.AutoArrayList.get(AutoArrayList.java:26)
org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.java:521)
org.apache.commons.beanutils.PropertyUtils.getIndexedProperty(PropertyUtils.java:428)
org.apache.commons.beanutils.PropertyUtils.getNestedProperty(PropertyUtils.java:770)
org.apache.commons.beanutils.PropertyUtils.getProperty(PropertyUtils.java:801)
org.apache.commons.beanutils.BeanUtils.setProperty(BeanUtils.java:881)
org.apache.commons.beanutils.BeanUtils.populate(BeanUtils.java:808)
org.apache.struts.util.RequestUtils.populate(RequestUtils.java:1252)
org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:821)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:254)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
com.zgsx.struts.tool.FilterEncoding.doFilter(FilterEncoding.java:50)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.23 logs.
import java.util.ArrayList;
// 如果有20行表单输入域但只输入了前三行,后面的输入域会变成空值,重写ArrayList 的get()会避免这一问题
public class AutoArrayList extends ArrayList {
/**
*
*/
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);
}