我有这个简单的表格:
<form id="myForm" method="POST" action="/project/upload" target="myFrame"
enctype="multipart/form-data">
Please select a file to upload : <input id="file" type="file" name="file" />
<input type="button" onclick="initSubmit()" value="upload" />
</form>
<iframe name="myFrame" height=0 width=0></iframe>
我得到以下错误:
org.springframework.web.multipart.MultipartException: The current request is not a multipart request
这里是我的javascript:
function submitForm() {
$("form#myForm").submit();
}
function initSubmit() {
$('form#myForm').submit(function () {
$.post('/project/upload', $('form#myForm').serialize(), function (data, textStatus) {
debugger;
alert("Yeah!, i can get the call back!");
});
return false;
});
submitForm();
}
这里是我的控制器方法:
@RequestMapping(value = "/upload", method = RequestMethod.POST)
public String handleFormUpload(
@RequestParam("file") MultipartFile file,HttpServletResponse response ) throws IOException{
if (!file.isEmpty()) {
// handle here
}
return imageURL;
}
我敢肯定,100%%的Ajax调用是无效的我的控制器
PS我这样做是为回调函数。 我需要接受IMAGEURL返回到客户端,显然形成回调复杂。
PS#2 - 定期提交表单没有JS此外,工作,但后来我不能得到回调上下文