gpt4 book ai didi

java - 使用表单 :input 为 Spring MVC 编写表单的正确方法是什么

转载 作者:行者123 更新时间:2023-11-30 08:20:47 25 4
gpt4 key购买 nike

目标

我想在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com