2016-07-29 67 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

相關問題