Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring bean name';的BindingResult或普通目标对象;命令';。春季例外_Spring_Jsp_Spring Mvc - Fatal编程技术网

Spring bean name';的BindingResult或普通目标对象;命令';。春季例外

Spring bean name';的BindingResult或普通目标对象;命令';。春季例外,spring,jsp,spring-mvc,Spring,Jsp,Spring Mvc,我开始学习SpringMVC3,我想在我的jsp文件中显示一个简单的“搜索表单” <form:form method="post" action="addGeo.html" > <table> <tr> <td> <input type="submit" value="<spring:message code="label.addzone"/

我开始学习SpringMVC3,我想在我的jsp文件中显示一个简单的“搜索表单”

<form:form method="post" action="addGeo.html" >
    <table>
        <tr>
            <td>        
                <input type="submit" value="<spring:message code="label.addzone"/>"/>
            </td>
        </tr>
    </table>    
</form:form>

<form:form method="post" action="maingeo.html" >
    <table>
        <tr>
            <td>
                <form:label path="codeZone"><spring:message code="label.area"/></form:label>
            </td>
            <td>    
                <form:input path="codeZone" />
            </td>        
            <td>
                <form:label path="type"><spring:message code="label.type"/></form:label>
            </td>  
            <td>
                <form:input path="type" />
            </td>        
            <td>
                <form:label path="codePostal"><spring:message code="label.departement"/></form:label>
            </td>
            <td>
                <form:input path="codePostal" />
            </td>
            <td>        
                <input  type="submit" value="<spring:message code="label.searchArea"/>"/>
            </td>
        </tr>
    </table> 
</form:form>

当我转到这个url页面时,出现了以下异常:java.lang.IllegalStateException:对于bean名称“command”,BindingResult和普通目标对象都不能作为请求属性使用。我想我忘了一些东西在我的表格里或者我的控制器里,但我不知道在哪里。此外,当我不想将特定模型发送到jsp视图时,我应该在方法参数上添加什么?

您需要编写一个包含表单字段的类——这种类称为命令对象/类

然后,在负责提供表单页面的控制器方法中,需要创建此命令对象的实例,将其放入模型中,然后让视图呈现它。模型中用于命令对象的名称必须与
标记的“Command”属性名称匹配。如果没有此属性,则默认名称为
command

@Controller public class RefGeoController {

   @Autowired private RefGeoService refgeoService;        

   @RequestMapping("/maingeo")
   public ModelAndView goSearchArea() {
      return new ModelAndView("maingeo", "searchCommand", new SearchCommand());
   }

   //only to prevent your next question: How to recive the committed form
   @RequestMapping("/maingeo.html", method = RequestMethod.POST)
   public ModelAndView handleSearch(SearchCommand searchCommand) {
      ... implement the search stuff
   } 
}


<form:form method="post" action="maingeo.html" command="searchCommand">
@Controller公共类RefGeoController{
@自连线专用RefGeoService RefGeoService;
@请求映射(“/maingeo”)
公共模型和视图goSearchArea(){
返回新的ModelAndView(“maingeo”,“searchCommand”,new searchCommand());
}
//只是为了避免你的下一个问题:如何接收提交的表单
@RequestMapping(“/maingeo.html”,method=RequestMethod.POST)
公共模型和视图手柄搜索(SearchCommand SearchCommand){
…实现搜索功能
} 
}

感谢您的快速回复,我有这个类和所有属性匹配fiels表单,模型中用于命令对象的名称也有put commandName,但总是有这个execption!似乎关注这一行:主要原因:bindingresult…@user3248251:将system.out.println添加到
goSearchArea()
方法中,并检查它是否真的被调用。我删除了第一个,始终是这个异常
@Controller public class RefGeoController {

   @Autowired private RefGeoService refgeoService;        

   @RequestMapping("/maingeo")
   public ModelAndView goSearchArea() {
      return new ModelAndView("maingeo", "searchCommand", new SearchCommand());
   }

   //only to prevent your next question: How to recive the committed form
   @RequestMapping("/maingeo.html", method = RequestMethod.POST)
   public ModelAndView handleSearch(SearchCommand searchCommand) {
      ... implement the search stuff
   } 
}


<form:form method="post" action="maingeo.html" command="searchCommand">