springmvc中web-xml中的配置
<servlet>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/classes/dispatcherServlet.xml
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>DispatcherServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
在spring的applicationContext.xml中配置:
<!-- 上传拦截,如最大上传值及最小上传值 -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- one of the properties available; the maximum file size in bytes -->
<property name="maxUploadSize" value="10000000" /><!-- 10M -->
</bean>
@RequestMapping(value = "/jsp/test/upload", method = RequestMethod.POST)// 将文件上传请求映射到该方法
public String handleFormUpload(// 设置请求参数的名称和类型
@RequestParam("file") MultipartFile mFile) { // 请求参数一定要与form中的参数名对应