HTTP Status 500

来源:互联网 发布:vc贪吃蛇c语言代码 编辑:程序博客网 时间:2024/06/05 10:10

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所对应的属性

[html] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. <form:form action="emp" method="POST" modelAttribute="employee">  
也可以通过commandName属性来指定bean名称
  1. <form:form action="emp" method="POST" commandName="employee">  

[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  1. @RequestMapping(value = "/emp",method=RequestMethod.GET)  
  2. public String input(Map<String,Object> map){  
  3. map.put("department",departmentDao.getDepartments());  
  4. map.put("employee"new Employee());  
  5. return "input";  
  6. }  
解决方法:
通过modelAttribute属性指定绑定的数据模型
原理:
如果没有指定该属性,则默认从request域对象中读取command的表单bean,即默认的modelAttribute 是command
如果该属性值也不存在,则会发生错误
springMVC认为表单一定是要进行回显的
即便是第一次来
也会去请求域找bean来匹配当前的表单值,即使不需要回显
原创粉丝点击