0

我到处搜索此错误并查看了此处具有相同标题的每个线程,在我的代码中进行了很多更改,但仍然存在错误。

它说:

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;

请帮忙。提前致谢。

4

1 回答 1

1

我忘了添加HttpServletRequest request到方法输入参数。我添加了它,它开始工作了。奇怪,但有效。:)

于 2013-11-07T20:50:55.023 回答