使用form:input为Spring MVC编写表单的正确方法是什么 [英] What's the correct way to write a form for Spring MVC with form:input

查看:269
本文介绍了使用form:input为Spring MVC编写表单的正确方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Spring MVC中编写一个表单,并始终使用form:input

I want to write a form in Spring MVC and use form:input consistently

<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>

控制器:

@RequestMapping("/insertChapter")
public String insertChapter(@ModelAttribute Chapter chapter) {
    if (chapter != null)
        infoService.insertChapter(chapter.getChapter(), chapter.getChapter());
        return "redirect:/getInfoListList";
}

但是服务器抱怨:

infoListList.jsp(行:83,列:7)根据TLD或标签文件,标签输入必须使用属性路径

infoListList.jsp (line: 83, column: 7) According to the TLD or the tag file, attribute path is mandatory for tag input

第83行是以下形式:input type ="submit" ...

line 83 is the one with form:input type = "submit"...

那么编写此jsp表单的正确方法是什么?我知道如何用没有form:input的形式写东西. form:input和just input有什么区别?混用form:input和just input(用于提交按钮)是否被认为是一种好的样式?

So what is the correct way to write this jsp form? I know how to write with form without form:input. What is the difference between form:input and just input? Is it considered a good style to mix form:input and just input (for submit button)?

推荐答案

您不能使用"form:input"标签提交表单. 要提交表单,您应该使用"form:button"标签 否则,您可以将type ="submit"用作html"input"标签.

you cannot use "form:input" tag to submit form. To submit the form you should use "form:button" tag or else you can use html "input" tag with type="submit".

<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>

这篇关于使用form:input为Spring MVC编写表单的正确方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆