您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

java.lang.IllegalStateException:BeanResult'category'的BindingResult和普通目标对象都不能用作请求属性

java.lang.IllegalStateException:BeanResult'category'的BindingResult和普通目标对象都不能用作请求属性

如果您要index.jsp通过进行操作http://localhost:8080/yourapp,我会假设您对此有<welcome- file>帮助。

这意味着,index.jspSpring无需进行任何预处理即可生成HTML。您正在尝试渲染此

<form:form method="POST" commandName="category" modelattribute="category" action="search_category">
    <form:input path="category_name" /> 
    <input type="submit" value="Submit">  
</form:form>

<form:form>Spring的标签库在哪里。首先,请注意您同时使用commandName和@H_421_1@modelattribute。这是多余的。使用一个或另一个,不要同时使用。其次,当您指定其中一个时,标记实现将查找HttpServletRequest具有指定名称属性。在您的情况下,没有将这样的属性添加HttpServletRequest属性中。这是因为Servlet容器index.jsp直接转发给您。

代替这样做,创建一个新的@Controller处理程序方法,该方法将向模型添加属性并转发给index.jsp视图。

@RequestMapping(value = "/", method = RequestMethod.GET)
public String welcomePage(Model model) {
    model.addAttribute("category", new Category()); // the Category object is used as a template to generate the form
    return "index";
}

你可以摆脱这个

<!--  Set the default page as index.jsp -->
<mvc:view-controller path="/" view-name="index"/>

另外,将所有mvc配置从applicationContext.xml文件移动到servlet-context.xml文件。那就是它的归属。这就是为什么。

java 2022/1/1 18:14:50 有446人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶