java – 没有commandName的弹簧窗体[复制]

前端之家收集整理的这篇文章主要介绍了java – 没有commandName的弹簧窗体[复制]前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
参见英文答案 > What causes “java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name ‘command’ available as request attribute”?5个
我是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>

我收到以下错误

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

我可以看到here,当你没有给commandName赋值时,它使用默认的’command’,但是,我是否必须配置其他任何东西?我应该在dispatcher-servlet.xml中放入一个’command’bean吗?那豆怎么样?

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

解决方法

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

所以,改变

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

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

命令对象确实不是必需的.仅当您使用Spring的表单时才强制使用,例如< form:form>< / form:form>使用以下库.

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

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

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

原文链接:https://www.f2er.com/java/120517.html

猜你在找的Java相关文章