HTTP Status 500 - java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute
发生的错误:在请求域例没有command这样的属性
<form:input path="lastName"/>
要想显示某个页面,必须在域对象里有一个bean,bean有跟表单path所对应的属性
<form:form action="emp" method="POST" modelAttribute="employee">@RequestMapping(value = "/emp",method=RequestMethod.GET)
public String input(Map<String,Object> map){
map.put("department",departmentDao.getDepartments());
map.put("employee", new Employee());
return "input";
}解决方法:
通过modelAttribute属性指定绑定的数据模型
原理:
如果没有指定该属性,则默认从request域对象中读取command的表单bean,即默认的modelAttribute 是command
如果该属性值也不存在,则会发生错误
springMVC认为表单一定是要进行回显的
即便是第一次来
也会去请求域找bean来匹配当前的表单值,即使不需要回显
本文探讨了Spring MVC中HTTP状态500错误的产生原因及解决办法,详细分析了java.lang.IllegalStateException异常出现的情景,尤其是在尝试访问不存在的'command'属性时。介绍了如何通过正确设置modelAttribute属性来避免此类问题。
4万+

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



