1 回答

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超13個(gè)贊
SpringMVC默認(rèn)是關(guān)閉fileupload功能的,開啟該能夠并驗(yàn)證文件上傳,需要做如下幾件事情:
第一:打開SpringMVC的文件上傳功能:
***-servlet.xml中配置:
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="100000"/>
<property name="maxInMemorySize" value="10240" />
</bean>
配置后,當(dāng)SpringMVC接受到multipartRequest的時(shí)候,就會(huì)把HttpServletRequest轉(zhuǎn)為MultipartHttpServletRequest類型,
第二步:創(chuàng)建上傳文件的file.jsp:
<form action="dynamicFields.action?method=uploadFile" method="post" enctype="multipart/form-data"><input type="file" name="myfile" id="myfile" value="" /><br/><input type="submit" value="確認(rèn)提交"></form>
一定不要漏掉enctype="multipart/form-data",否則web容器認(rèn)為這不是一個(gè)MultipartRequest請(qǐng)求,
會(huì)報(bào)錯(cuò)org.springframework.web.multipart.MultipartException: The current
request is not a multipart request。
- 1 回答
- 0 關(guān)注
- 1082 瀏覽
添加回答
舉報(bào)