Java – spring form without commandname [copy]
See English answer > what causes "java.lang.illegalstateexception: neither bindingresult nor plain target object for bean name 'command' available as request attribute"? 5
<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>
I received the following error:
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute
I can see here that when you do not assign a value to commandname, it uses the default 'command', but do I have to configure anything else? I should be in dispatcher servlet Put a 'command' bean in XML? How about the beans?
I just want a form to send information to the controller Do I really have to create a bean to support it?
Solution
If you don't need command objects at all, avoid spring forms and simply use HTML forms
So, change
<form:form action="getReportFile.html" method="post">
.
.
.
</form:form>
to
<form action="getReportFile.html" method="post">
.
.
.
</form>
The command object is really not required It is mandatory only when you use spring's forms. For example, < form: Form > < / form: Form > uses the following libraries
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
If you use an HTML form, you must use request The getparameter ("paramname") method receives the request parameters
http://forum.springsource.org/showthread.php?83532 -how-to-have-form-without-command-object&p=279807#post279807
