来自jsp表单的请求不正确

时间:2014-03-27 22:49:25

标签: java jsp

当我尝试提交我的表单时,tomcat会抛出“客户端发送的请求在语法上是不正确的。” 这是我的jsp表单。请帮帮我。

<form:form method="POST" commandName="articleDTO" id="categoryForm">
    <form:errors path="*" />
    <td>Title</td>
    <td><form:input path="title" /></td>

    <table>
        <thead>
            <tr>
                <th>Category</th>
                <th></th>
            </tr>
        </thead>
        <c:forEach items="${articleDTO.categories}" var="Category"
            varStatus="i" begin="0">
            <td><form:select path="categories[${i.index}]">
                    <form:option value="NONE" label="--- Select ---" />
                    <form:options items="${categoryList}" />
                </form:select></td>
        </c:forEach>
    </table>
    <td colspan="3"><input type="submit" value="GG" /></td>
</form:form>

电脑板:

    @RequestMapping(method = RequestMethod.GET)
public ModelAndView getAdminPage() {
    return new ModelAndView("admin_page").addObject("categoryList",
            categoryService.getAllCategories()).addObject("articleDTO", new ArticleDTO());
}

@RequestMapping(method = RequestMethod.POST)
public ModelAndView ondas(ArticleDTO articleDTO) {
    return new ModelAndView("done").addObject("article", articleDTO);
}

DTO:

private String title;

@NotEmpty
@Range(min = 100, max = 6000)
private String description;

@NotEmpty
private List<Category> categories = new ArrayList<Category>();

public ArticleDTO() {
    Category category = new Category();
    category.setTitle("news");
    category.setId(1L);
    Category category1 = new Category();
    category1.setTitle("news1");
    category1.setId(2L);
    categories.add(category1);
    categories.add(category);
}

我试图从文章类别的用户列表中获取

1 个答案:

答案 0 :(得分:0)

我几乎肯定你的POST有验证问题......:)

尝试将您的方法更改为此类内容。

@RequestMapping(method = RequestMethod.POST)
public ModelAndView ondas(ArticleDTO articleDTO, BindingResult result) {

    if (result.hasErrors()) {
        return new ModelAndView("admin_page").addObject("categoryList",
        categoryService.getAllCategories()).addObject("articleDTO", new ArticleDTO());
    }
    return new ModelAndView("done").addObject("article", articleDTO);
}