为什么我什么都配置好了,就是接收不到来自multipart/form-data的<form>参数?
这是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";
}
然后就报错:
求解,搞了好久
換個名字用uploadFile試試
導入這個包了嗎
spring配置裡加這句試試,我沒詳細研究過sping上傳文件,但剛好做過的專案裡有這種需求
抱歉沒注意你已經加了這句,那可能我沒辦法幫你了