為什么我什么都配置好了,就是接收不到來自multipart/form-data的<form>參數(shù)?
這是jsp:
<body>
<form action="/save" method="post" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit"/>
</form>
</body>
這是springmvc配置文件:
<bean id="commonsMultipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="utf-8"></property>
<property name="maxUploadSize" value="10485760000"></property>
<property name="maxInMemorySize" value="40960"></property>
</bean>
<!-- 掃描路徑 -->
<context:component-scan base-package="cn.liangjiateng.controller"/>
<context:component-scan base-package="cn.liangjiateng.service"/>
<mvc:annotation-driven/>
<!-- 視圖層配置 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
id="internalResourceViewResolver">
<!-- 前綴 -->
<property name="prefix" value="/WEB-INF/jsp/" />
<!-- 后綴 -->
<property name="suffix" value=".jsp" />
</bean>
這是controller:
@RequestMapping(value = "/save",method = RequestMethod.POST)
public String save(@RequestParam("file") MultipartFile file, HttpServletRequest request){
System.out.println(file.getOriginalFilename());
return "upload";
}
然后就報錯:
求解,搞了好久
學(xué)習(xí)是最好的投資!
導(dǎo)入這個包了嗎
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.1</version>
</dependency>
<!-- SpringMVC上傳文件時,需要配置MultipartResolver處理器 -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- 指定所上傳文件的總大小不能超過200000KB。注意maxUploadSize屬性的限制不是針對單個文件,而是所有文件的容量之和 -->
<property name="maxUploadSize" value="200000000"/>
</bean>
spring配置裡加這句試試,我沒詳細(xì)研究過sping上傳文件,但剛好做過的專案裡有這種需求
抱歉沒注意你已經(jīng)加了這句,那可能我沒辦法幫你了