框架:spring
现象:jsp页面使用foreach循环输出list,保存时并将修改后的值返回给后台页面。
异常:org.springframework.beans.InvalidPropertyException: Invalid property 'list[256]' of bean class [...]: Index of out of bounds in property path 'list[256]'; nested exception is java.lang.IndexOutOfBoundsException: Index: 256, Size: 256
在jsp传值时直接保存,并没有进入后台
原因:DataBinder中有如下定义:
public class DataBinder implements PropertyEditorRegistry, TypeConverter {
/** Default object name used for binding: "target" */
public static final String DEFAULT_OBJECT_NAME = "target";
/** Default limit for array and collection growing: 256 */
public static final int DEFAULT_AUTO_GROW_COLLECTION_LIMIT = 256;
private int autoGrowCollectionLimit = DEFAULT_AUTO_GROW_COLLECTION_LIMIT; 解决方法:在自己的Controller类中,加入以下代码
@InitBinder
protected void initBinder(WebDataBinder binder) {
binder.setAutoGrowNestedPaths(true);
binder.setAutoGrowCollectionLimit(1024);
}
本文探讨了在Spring MVC框架中使用JSP页面时遇到的一个常见问题:DataBinder的InvalidPropertyException异常。当JSP页面使用foreach循环输出list并尝试保存修改后的值时,会触发该异常。文章深入分析了问题产生的原因,并提供了一个简单的解决方案,通过调整Controller中的DataBinder配置来避免此异常。
2178

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



