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

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

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

如果您要

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

这意味着,

index.jsp
Spring无需进行任何预处理即可生成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
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
文件。那就是它的归属。这就是为什么。



欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5167956.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-11-18
下一篇 2022-11-18

发表评论

登录后才能评论

评论列表(0条)

保存