[英]What's the correct way to write a form for Spring MVC with form:input
I want to write a form in Spring MVC and use form:input consistently 我想在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";
}
but the server complained: 但是服务器抱怨:
infoListList.jsp (line: 83, column: 7) According to the TLD or the tag file, attribute path is mandatory for tag input infoListList.jsp(行:83,列:7)根据TLD或标签文件,属性路径对于标签输入是必需的
line 83 is the one with form:input type = "submit"... 第83行的形式为:输入类型=“提交” ...
So what is the correct way to write this jsp form? 那么编写此jsp表单的正确方法是什么? I know how to write with form without form:input. 我知道如何用没有form:input的形式写东西。 What is the difference between form:input and just input? form:input和just input有什么区别? Is it considered a good style to mix form:input and just input (for submit button)? 混合form:input和just input(用于提交按钮)是否被认为是一种好的样式?
you cannot use "form:input" tag to submit form. 您不能使用“ form:input”标签提交表单。 To submit the form you should use "form:button" tag or else you can use html "input" tag with type="submit". 要提交表单,您应该使用“ 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.