没有commandName的Spring表单

编程入门 行业动态 更新时间:2024-10-28 02:36:10
本文介绍了没有commandName的Spring表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是Spring的新手,我遇到了问题。我有一个用于向控制器发送信息的表单。我不需要或者想要一个bean备份表单,所以我在表单空白处留下了 commandName 属性,如下所示:

I'm new to Spring, and I have a problem. I have a form which is used to send information to the controller. I don't need or want to have a bean backing up the form so I left the commandName attribute in the form blank like this:

<form:form action="getReportFile.html" method="post"> <table> <tr> <td><form:label path="field1">Field1:</form:label></td> </tr> <tr> <td><form:select path="field1" items="${FieldMap}" /> </td> </tr> <tr> <td><form:label path="field2">Field2:</form:label></td> </tr> <tr> <td><form:input path="field2"/></td> </tr> <tr> <td><input type="submit" value="Submit" /></td> </tr> </table> </form:form>

我收到以下错误:

java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute

我可以看到这里当你没有给 commandName 赋值时,它使用默认的 'command',但是,我还需要配置其他内容吗?我应该在 dispatcher-servlet.xml 中放入一个'命令' bean吗?那个bean怎么样?

I could see here that when you don't give a value to commandName it uses the default 'command', but then, Do I have to configure anything else? should I put a 'command' bean in the dispatcher-servlet.xml? How would that bean?

我只想要一个表单将信息发送给控制器。 我真的需要创建一个bean来支持吗?

I just want a form to send the information to the controller. Do I really have to create a bean to back it?

推荐答案

如果你不需要一个命令对象,然后避免使用Spring表单,只需使用HTML表单。

If you don't need a command object at all, then avoid the Spring form and simply use an HTML form.

所以,更改

<form:form action="getReportFile.html" method="post"> . . . </form:form>

<form action="getReportFile.html" method="post"> . . . </form>

命令对象确实不是必需的。只有当您使用Spring的表格(例如< form:form>< / form:form> )时,才需要使用以下库。

The command object is indeed not mandatory. It is mandatory only if you use the Spring's form like <form:form></form:form> using the following library.

<%@taglib prefix="form" uri="www.springframework/tags/form"%>

您必须使用 request.getParameter(paramName接收请求参数)方法,如果您使用HTML表单。

You have to receive the request parameters using the request.getParameter("paramName") method, if you use an HTML form.

如果你没有表格支持bean,你不能使用Spring 标签,因为它确实需要一个! 上的path属性该标记应该指定模型bean的属性的数据绑定路径。

if you don't have a form backing bean, you can't use the Spring tag since it does require one! Your "path" attribute on that tag is supposed to specify the path to the model bean's property for data binding.

http:// forum.springsource/showthread.php?83532-how-to-have-form-without-command-object&p=279807#post279807

更多推荐

没有commandName的Spring表单

本文发布于:2023-11-09 09:08:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571986.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:表单   commandName   Spring

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!