没有commandName的Spring表单

Chr*_*lma 6 java spring spring-mvc java-ee

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

<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>
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute
Run Code Online (Sandbox Code Playgroud)

我可以在这里看到,当你没有给commandName它一个值使用默认值'command',但是,那么,我是否必须配置其他任何东西?我应该把'command'豆子放进去dispatcher-servlet.xml吗?那豆怎么样?

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

Lio*_*ion 8

如果您根本不需要命令对象,那么请避免使用Spring表单并简单地使用HTML表单.

所以,改变

<form:form action="getReportFile.html" method="post">
     .
     .
     .
</form:form>
Run Code Online (Sandbox Code Playgroud)

<form action="getReportFile.html" method="post">
     .
     .
     .
</form>
Run Code Online (Sandbox Code Playgroud)

命令对象确实不是必需的.只有在使用Spring的表单时才强制<form:form></form:form>使用以下库.

<%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
Run Code Online (Sandbox Code Playgroud)

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


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

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


归档时间:

查看次数:

9785 次

最近记录:

9 年,7 月 前