如果您要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
和@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
文件。那就是它的归属。这就是为什么。