0
我在Spring MVC應用程序中看到很多關於stackoverflow關於多部分文件上傳問題的答案。 一步一步我確信我不會重複其他人的錯誤。Spring mvc多部分文件上傳
這裏是我的形式
<form class="form-horizontal" data-toggle="validator"
id="track_existing_repair"
method="post"
action="/euo/testUpload.htm"
enctype="multipart/form-data">
...
<div class="form-group required">
<label class="control-label col-sm-4" for="proofOfPurchaseInput">Select File:</label>
<div class="col-sm-8">
<input name="proofOfPurchase"
id="proofOfPurchaseInput"
type="file"
required/>
</div>
</div>
...
</form>
在POM文件我有依賴
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.2</version>
</dependency>
宣佈multipartResolver在app-servlet.xml中
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- max upload size in bytes -->
<property name="maxUploadSize" value="20971520" /> <!-- 20MB -->
<!-- max size of file in memory (in bytes) -->
<property name="maxInMemorySize" value="1048576" /> <!-- 1MB -->
</bean>
方法映射到控制器類要求
@RequestMapping(value = {"/testUpload"},headers = "Content-Type=multipart/form-data", method = RequestMethod.POST)
public String testUpload(
@RequestPart(value = "proofOfPurchase", required = false) MultipartFile proofOfPurchaseFile
,HttpServletRequest request
) throws InvalidFormatException, IOException {
if(proofOfPurchaseFile != null){
readFile(proofOfPurchaseFile);
}
return NAV_HOME;
}
我試圖@RequestParam代替@RequestPart
在不需要=假我有 「必需請求部分 'proofOfPurchase' 不存在」 響應,所以我使它不需要 只能在調試器中進入檢查請求
所以當我停在調試器時,我並不感到驚訝,請求對象顯示我收到了該文件,甚至存儲在jBoss臨時文件夾中。
可否請你指出我可能會錯過什麼春天不能看到上傳的文件?