目标
我想在 Spring MVC 中编写一个表单并一致地使用 form:input
<form:form method="post" action="/insertChapter" modelAttribute="Chapter">
<form:input type="hidden" path="chapter" value="${info.chapter}"/>
<form:input path="title" />
<form:input type="submit" value="Insert" />
</form:form>
Controller :
@RequestMapping("/insertChapter")
public String insertChapter(@ModelAttribute Chapter chapter) {
if (chapter != null)
infoService.insertChapter(chapter.getChapter(), chapter.getChapter());
return "redirect:/getInfoListList";
}
但是服务器提示:
infoListList.jsp (line: 83, column: 7) According to the TLD or the tag file, attribute path is mandatory for tag input
第 83 行是 form:input type = "submit"...
问题
那么这个jsp表单的正确写法是什么呢?我知道如何在没有 form:input 的情况下使用 form 编写。 form:input 和 just input 有什么区别?混合 form:input 和 just input (用于提交按钮)是否被认为是一个好的风格?
最佳答案
您不能使用“form:input”标签来提交表单。 要提交表单,您应该使用“form:button”标签 或者您可以使用带有 type="submit"的 html“input”标签。
<body>
<form:form modelAttribute="pizza" action="add" method="POST">
Pizza name:<form:input path="name" />
<br>
<br>
Pizza price:<form:input path="price" />
<br>
<br>
Select Base<form:select id="baseList" path="base" items="${baseList}"
itemLabel="name" itemValue="baseId"></form:select>
<br>
<br>
Select Toppings
<form:checkboxes items="${toppingList}" itemLabel="name"
itemValue="toppingId" path="toppings" />
<form:button>Submit</form:button>
</form:form>
关于java - 使用表单 :input 编写 Spring MVC 表单的正确方法是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25715891/