报错信息:
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute
错误原因:
使用了springMVC中带有的form表单标签;
该标签具有自动回显的功能,回显的内容就在request域中分为两种情况:
① (不指定modelAttribute属性) 默认回显request中属性名为command的元素,如果没有则报此错误;
② (指定modelAttribute属性)按照modelAttribute设定的值在request中寻找,如果没有则报此错误;
修改方法:
方法一、在controller处理方法中向request域中保存名为command的元素
// 设置form回显
map.put("command",new Employee());
方法二、通过modelAttribute属性指定一个request域中已经存在的回显对象
<form:form action="${pageContext.request.contextPath}/emp" method="post" modelAttribute="eee">