Java Spring IO POST表单正在重定向到错误的URL-Thymeleaf
我有一个表格,用于在我正在编码的网站上上传文件。从URL{docId}它应该指向URL,然后重定向回userDashboard 但是,当我提交表单时,它会将我带到其中,因此它会将/uploadRevisionLanding附加到URL,而不是从根目录开始。如果这不是正确的术语,很抱歉 我使用的是SpringIO和Thymeleaf,我还编写了其他代码,以类似的方式工作,效果很好 我的表格Java Spring IO POST表单正在重定向到错误的URL-Thymeleaf,java,html,spring,forms,spring-mvc,Java,Html,Spring,Forms,Spring Mvc,我有一个表格,用于在我正在编码的网站上上传文件。从URL{docId}它应该指向URL,然后重定向回userDashboard 但是,当我提交表单时,它会将我带到其中,因此它会将/uploadRevisionLanding附加到URL,而不是从根目录开始。如果这不是正确的术语,很抱歉 我使用的是SpringIO和Thymeleaf,我还编写了其他代码,以类似的方式工作,效果很好 我的表格 <form name="upload" action="/" th:action="@{uploadR
<form name="upload" action="/" th:action="@{uploadRevisionLanding}" th:object="${document}" method="POST" enctype="multipart/form-data">
<div class="container">
<br />
<div class="row">
<div class="col-md-12">
<div class="panel panel-default">
<div class="panel-heading">
<strong>Upload files</strong> <small>
</small>
</div>
<div class="panel-body">
<label class="control-label" >Title:</label>
<label class = "docTitle" th:text="${document.title}" />
<label class="control-label">Select File:</label>
<input id="input-2" type="file" name="file" class="file"/>
<button type="button" class="btn btn-default file-preview-clear" value="Reset">
<span class="glyphicon glyphicon-remove"></span>
Clear </button>
<!-- file-preview-input -->
<button type="submit" class="btn btn-labeled btn-primary" value="Submit">
<span class="btn-label"><i class="glyphicon glyphicon-upload"></i>
</span> Upload </button>
<input type="hidden"
name="${_csrf.parameterName}"
value="${_csrf.token}"/>
</div>
</div>
</div>
</div>
</div>
在控制器方法中,我尝试返回URL字符串,包括前面的/已解决的URL字符串和未解决的URL字符串!我需要将th:action=@{uploadRevisionLanding}作为th:action=@{/uploadRevisionLanding}使用前面的/使其成为相对于服务器根目录的上下文。它在另一个页面上没有它也能正常工作,这与我的页面略有不同,这让我很困惑
@GetMapping("/uploadRevision/{docId}")
public String uploadRevision(Model model, @PathVariable("docId") long docId) {
/* Do something */
return "/uploadRevision";
}
@PostMapping("/uploadRevisionLanding")
public RedirectView handleRevisionUpload (@RequestParam("file") MultipartFile file,
RedirectAttributes redirectAttributes,
@ModelAttribute Document document) {
/* Load logged user */
/* Set branch for file */
return new RedirectView("/uploadRevisionLanding");
}
@GetMapping("/uploadRevisionLanding")
public ModelAndView uploadRevisionLanding() { return new ModelAndView("userDashboard"); }