Reputation: 33974
I have a simple HTML form:
<form id="marketplaceForm" enctype="multipart/form-data" method="post">
<select name="category">
<option selected ></option>
<option value="Sales">Sales</option>
<option value="Marketing" >Marketing</option>
</select>
<textarea type="text" id="marketplaceDesc" name="description" value="" class="creattbleArea"></textarea>
<input type="text" id="marketplaceName" name="templateName" >
<input type="file" id="marketplaceLogo" name="logo">
<input type="submit" value="Save" id="update" />
<input type="text" id="marketplacePrice" name="price">
</form>
I need to auto bind this form when I submit it. This works fine:
@RequestMapping(value = "/.....", method = RequestMethod.POST)
public String PublishForm() {
But this throws the following error:
HTTP Status 400 - The request sent by the client was syntactically incorrect
@RequestMapping(value = "/PublishApplication.htm", method = RequestMethod.POST)
public String PublishForm(@RequestParam("templateName") String templateName,
@RequestParam("category") String category,
@RequestParam("price") String price,
@RequestParam("description") String description
) {
Can any one help me?
Update: I have found that if I remove enctype="multipart/form-data"
from the HTML form, it works. Now my question is how to make it work with enctype="multipart/form-data"
.
Upvotes: 2
Views: 5842
Reputation: 16809
I think you may be missing the Multipart resolver from your configuration.
do you have something like this in your configuration?
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="250000"/>
</bean>
see here for the offical spring documentation on the matter.
Upvotes: 7
Reputation: 33735
First of all, make sure the binding to PublishApplication.htm
really works. You are using this mapping in your controller, but you haven't specified it in action
param of <form>
tag. So you may end up with posting the form to some different controller, and server rejects your request. Of course this will not happen if you are using the same controller for both - displaying form and submiting it, and you have aplied RequestMapping
annotation at class level.
There is another issue with your controller though. You are not specifying logo
as @RequestParam
in PublishForm
method. I'm not sure if this is not messing up form autobinding. If I recall correctly, those params are required by default.
Upvotes: 1