I was fumbling to use RequestMethod.PUT
(and RequestMethod.DELETE
) as described in my previous question. At last the approach worked but when I designate a method with RequestMethod.PUT
in my Spring controller, this method is called when the form is submitted but presumably it appears that the request is not regarded as a multipart request even though the form has that attribute enctype="multipart/form-data"
.
The form is as follows something similar to the previous question.
<form:form id="mainForm" name="mainForm" method="put" action="Temp.htm" enctype="multipart/form-data" commandName="tempBean">
<input type="file" id="myFile" name="myFile"/>
<input type="text" id="myText" name="myText"/>
<input type="submit" id="btnSubmit" name="btnSubmit" value="Submit"/>
</form:form>
and the method in Spring which is invoked when a submit button is clicked is as follows.
@RequestMapping(method={RequestMethod.PUT}, value={"admin_side/Temp"}, headers={"content-type=multipart/form-data"})
public String update(@RequestParam("myText") String text, @ModelAttribute("tempBean") TempBean tempBean, BindingResult error, Map model, HttpServletRequest request, HttpServletResponse response)
{
System.out.println(ServletFileUpload.isMultipartContent(request)+" : "+text);
return "admin_side/Temp";
}
Other request parameters are obtained like @RequestParam("myText") String text
and even with request.getParameter("myText")
but the the method invocation of ServletFileUpload.isMultipartContent(request)
returns false (also request.getParameter("myFile")
returns null
) which means that the request doesn't appear to be a multipart request.
When the request method is changed to RequestMethod.POST
, everything goes fine.
How to get multipart contents using the PUT
method?