2016-07-29 65 views
0

有人可以帮我这个错误无论BindingResult也不是为bean名称平原目标对象zipbean'可以作为请求属性

的index.jsp

<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%> 
<html> 
<head> 
<body> 
<jsp:include page="links.jsp"/> 
<script src="<%=request.getContextPath()%>/js/welcome.js"></script> 
<form:form action="${pageContext.request.contextPath}/Customer" method="POST" modelAttribute="zipbean"> 
<input type="text" id="zip" name="zip" class="form-control search ui-autocomplete" onkeypress=" return validate(event)" onkeydown="getData('${pageContext.request.contextPath}/ZipController/autoComplete');" /> 
<form:button path="zipone" class="btn btn-success">Get a Quote</form:button> 
</center> 
</form:form> 
</body> 
</html> 

CustomerController

@Controller 
@RequestMapping("/Customer") 
public class CustomerController 
{ 
    @Autowired 
    ZipDao zipDao; 
     @RequestMapping(method = RequestMethod.GET) 
     public String init(HttpServletRequest request,HttpServletResponse responce,ModelMap model) 
     { 
      System.out.println("customer page started"); 
      ZipBean zipbean=new ZipBean(); 
      model.addAttribute("zipbean", zipbean); 
      return "customer"; 
     } 
} 

而且我有一些文本框客户页面显示

回答

0

我猜你应该更换

<input type="text" id="zip" name="zip" 

<form:input type="text" id="zip" path="zip" 

,使其成为春豆

的一部分

请注意,name属性成为path作为t的一部分他的适应化弹簧标签

此外,还要确保ZipBean类有一个private String zip; +一个getZip()setZip(String zip)方法

最后,确保匹配的控制器将处理POST请求具有正确的@ModelAttribute但我想你问你为什么你的jsp不会首先加载

+0

如果在同一个jsp中有select属性会怎么样。我必须添加表单:select? –

+0

是 - 看看春天的文档,但语法是99%类似于经典的标签:)主要是名称= 属性中的路径 – niilzon

相关问题