获取java.lang.IllegalStateException:bean name';的BindingResult或普通目标对象;命令';可用作请求属性

获取java.lang.IllegalStateException:bean name';的BindingResult或普通目标对象;命令';可用作请求属性,java,spring,spring-mvc,Java,Spring,Spring Mvc,获取java.lang.IllegalStateException:在spring 3.0中,bean名称“command”的BindingResult和普通目标对象都不能作为请求属性使用。我如何解决它 下面是文件的代码 index.jsp <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@taglib uri="http://w

获取
java.lang.IllegalStateException:在spring 3.0中,bean名称“command”的BindingResult和普通目标对象都不能作为请求属性使用。我如何解决它

下面是文件的代码

index.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Form handling</title>
</head>
<body>
     <form:form action="/emp/showEmployee" method="POST">
 <table>
<tbody>
 <tr><td>Employee Name: </td><td><form:input path="empName"/></td></tr>
 <tr><td>Employee Skill: </td><td><form:input path="empSkill"/></td></tr>
 <tr><td><input type="submit" value = "Submit"></td></tr>
 </tbody>
</table>
</form:form>
</body>
 </html>
EmployeeForm.java(Bean类)


将其添加到表单元素:

<form:form action="/emp/showEmployee" method="POST" modelAttribute="employee">

这应该像将
modeldattribute
添加到表单标记中一样,如下所示:
在您告诉我要提及的内容之后,我仍然收到错误“java.lang.IllegalStateException:bean name'employee'的BindingResult和普通目标对象都不能作为请求属性使用”。我已经更新了我的答案,希望它能帮助您
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:p="http://www.springframework.org/schema/p"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:mvc="http://www.springframework.org/schema/mvc"
   xsi:schemaLocation="http://www.springframework.org/schema/beans 
                       http://www.springframework.org/schema/beans/spring-beans.xsd
                       http://www.springframework.org/schema/context 
                       http://www.springframework.org/schema/context/spring-context.xsd
                       http://www.springframework.org/schema/mvc
                       http://www.springframework.org/schema/mvc/spring-mvc.xsd">
 package com.springmvctut.controller;

 import org.springframework.stereotype.Controller;
 import org.springframework.ui.ModelMap;
 import org.springframework.web.bind.annotation.ModelAttribute;
 import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RequestMethod;
 import org.springframework.web.servlet.ModelAndView;

 import com.springmvctut.bean.EmployeeForm;

 @Controller
 public class EmployeeController {

@RequestMapping(value = "/employee", method = RequestMethod.GET)
  public ModelAndView employee() {
    return new ModelAndView("employeeForm", "command", new EmployeeForm());
   }
@RequestMapping(value = "/showEmployee", method = RequestMethod.POST)
public String showEmployee(@ModelAttribute("SpringWeb")EmployeeForm employeeForm, ModelMap modelMap){

    modelMap.addAttribute("name", employeeForm.getEmpName());
    modelMap.addAttribute("skill", employeeForm.getEmpSkill());
    return "employeedetails";

}

}
package com.springmvctut.bean;

public class EmployeeForm {

private String empName;
private String empSkill;
public String getEmpName() {
    return empName;
}
public void setEmpName(String empName) {
    this.empName = empName;
}
public String getEmpSkill() {
    return empSkill;
}
public void setEmpSkill(String empSkill) {
    this.empSkill = empSkill;
}
public String toString(){
      return "Employee name-"+empName+" Employee Skill-"+empSkill;
     }

}
<form:form action="/emp/showEmployee" method="POST" modelAttribute="employee">
@ModelAttribute
public void addEmplployeeTomModel(Model model){
     model.addAttribute("employee",new EmployeeForm())
}


@RequestMapping(value = "/showEmployee", method = RequestMethod.POST)
public String showEmployee(@ModelAttribute("employee")EmployeeForm employeeForm, ModelMap modelMap){

    modelMap.addAttribute("name", employeeForm.getEmpName());
    modelMap.addAttribute("skill", employeeForm.getEmpSkill());
    return "employeedetails";

}