【发布时间】:2020-12-26 06:45:39
【问题描述】:
我已参考以下链接上传文件,但我不断收到
https://www.baeldung.com/spring-file-upload
这在我的 Thymeleaf 文件中有:
<div>
<form method="POST" action="esubmission/submitter/uploadFile" enctype="multipart/form-data" onclick="disableOnBeforeUnload()" >
<table>
<tr>
<td><label path="file">Select a file to upload</label></td>
<td><input type="file" name="file" /></td>
</tr>
<tr>
<td><input type="submit" value="Submit"/></td>
</tr>
</table>
</form>
</div>
这是我的javascript函数
function disableOnBeforeUnload() {
window.removeEventListener("beforeunload", windowClosedOrReloaded);
}
这是我的控制器:
@RequestMapping(value = "/uploadFile", method = RequestMethod.POST)
public String submit(@RequestParam("file") MultipartFile file, ModelMap modelMap) {
modelMap.addAttribute("file", file);
return "fileUploadView";
}
如您所见,我在控制器中调用了函数,但出现 404 错误
2020-09-07 16:19:05.332 DEBUG 81932 --- [nio-8080-exec-3] o.s.w.s.r.ResourceHttpRequestHandler : Resource not found
[2020-09-07 16:19:05,332] DEBUG o.s.w.s.r.ResourceHttpRequestHandler - Resource not found
2020-09-07 16:19:05.332 DEBUG 81932 --- [nio-8080-exec-3] o.s.web.servlet.DispatcherServlet : Completed 404 NOT_FOUND
我错过了什么??
我也尝试过使用 ajax 调用,如下所示:
function uploadDocument(){
$.ajax({
type: "POST",
contentType: "application/json",
url: "/appName/role/uploadFile/",
timeout: 100000,
success: function (result) {
console.log("SUCCESS");
},
error: function (e) {
console.log("ERROR: ", e);
},
done: function (e) {
console.log("DONE");
}
});
}
【问题讨论】:
-
这个
/appName/role/uploadFile/url 对吗? 404 仅表示您引用的网址不正确或不存在,因此请确保网址是否正确。 -
是的,网址是正确的。我只是将其更改为隐藏真实值。
标签: ajax spring-boot file spring-mvc