没有commandName的Spring表单 [英] Spring form without commandName

查看:152
本文介绍了没有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="http://www.springframework.org/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.org/showthread.php?83532-how-to-have-form-without-command-object&p=279807#post279807

这篇关于没有commandName的Spring表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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