2013-04-22 116 views
0

我到处搜索这个错误,并查看每个单独的线程在同一个标​​题,在我的代码中改变了很多,但仍然存在错误。客户端发送的请求在语法上是不正确的,Spring with Hibernate Annotations

它说:

HTTP Status 400 - 

type Status report 

message 

description The request sent by the client was syntactically incorrect. 
Apache Tomcat/7.0.35 

我的控制器代码:

@RequestMapping(value = "/manageInventory.htm", method = RequestMethod.GET) 
    public ModelAndView manageInventory(HttpSession session) { 

     ArrayList<Product> products = new ArrayList<Product>(); 
     Manufacturer manufacturer = (Manufacturer) manufacturerDAO 
       .getByUsername(((UserAccount) session.getAttribute("user")) 
         .getUsername()); 
     products = productDAO.getProductListByManufacturer(manufacturer 
       .getManufacturerName()); 
     System.out.print(products.get(0).getProductName()); 
     ModelAndView view = new ModelAndView("manageInventory"); 
     view.addObject("products", products); 
     InventoryItem inventoryItem = new InventoryItem(); 
     view.addObject("inventoryItem", inventoryItem); 
     return view; 
    } 

    @RequestMapping(value = "/manufacture.htm", method = RequestMethod.POST) 
    public ModelAndView manufactureProduct(HttpSession session, BindingResult result, 
      @ModelAttribute("inventoryItem") @Valid InventoryItem inventoryItem) { 

     System.out.print(result.getErrorCount()+" "+result.getAllErrors()); 

     ModelAndView view = null; 
     if(!result.hasErrors()) 
     { 
     Manufacturer manufacturer = manufacturerDAO 
       .getByUsername(((UserAccount) (session.getAttribute("user"))) 
         .getUsername()); 
     inventoryItem.setAvailability(true); 
     inventoryItem.setManufacturer(manufacturer); 
     manufacturer.getInventory().add(inventoryItem); 
     manufacturerDAO.update(manufacturer); 
     view = new ModelAndView("done"); 
     } 
     else 
     { 
      view = new ModelAndView("manageInventory"); 
     } 
     return view; 

    } 

第一种方法是增加inventoryItem到模型中,我取,对于验证之后。

我使用的地砖等等,我给这家瓷砖是:

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%> 
<body> 
    <h2>Add Inventory</h2> 
    <br /> 
    <form:form modelAttribute="inventoryItem" action="manufacture.htm" method="post"> 
     <table> 
      <tr> 
       <td>Select Product:</td> 
       <td><form:select path="product"> 
         <c:forEach var="product" items="${products}"> 
          <form:option value="${product}">${product.productName}</form:option> 
         </c:forEach> 
       </form:select></td> 
       <td>Select Quantity:</td> 
       <td> 
       <form:input path="quantity" placeholder="Quantity"/><br /> 
       <font color="red"><form:errors path="quantity"/> </font> 
       </td> 
      </tr> 
      <tr> 
       <td colspan="2" align="center"><input type="submit" value="Manufacture"> 
       </td> 
      </tr> 
     </table> 
    </form:form> 
</body> 

我的POJO具有以下验证:

@NotNull 
    private int quantity; 

请帮助。提前致谢。

回答

1

我忘了给方法输入参数添加HttpServletRequest request。 我加了它,它盯着工作。奇怪,但工作。 :)

相关问题