SpringMVC中的文件上传(大小超限跳转控制)

来源:互联网 发布:网络机顶盒安装app 编辑:程序博客网 时间:2024/06/07 07:12
<?xml version="1.0" encoding="UTF-8"?>  <beans xmlns="http://www.springframework.org/schema/beans"      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"      xmlns:mvc="http://www.springframework.org/schema/mvc"      xmlns:context="http://www.springframework.org/schema/context"      xsi:schemaLocation="http://www.springframework.org/schema/beans                           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd                          http://www.springframework.org/schema/mvc                          http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd                          http://www.springframework.org/schema/context                           http://www.springframework.org/schema/context/spring-context-3.0.xsd">      <context:component-scan base-package="com.jadyer"/>            <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">          <property name="prefix" value="/WEB-INF/jsp/"/>          <property name="suffix" value=".jsp"/>      </bean>            <!-- SpringMVC上传文件时,需要配置MultipartResolver处理器 -->      <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">          <property name="defaultEncoding" value="UTF-8"/>          <!-- 指定所上传文件的总大小不能超过200KB。注意maxUploadSize属性的限制不是针对单个文件,而是所有文件的容量之和 -->          <property name="maxUploadSize" value="200000"/>      </bean>            <!-- SpringMVC在超出上传文件限制时,会抛出org.springframework.web.multipart.MaxUploadSizeExceededException -->      <!-- 该异常是SpringMVC在检查上传的文件信息时抛出来的,而且此时还没有进入到Controller方法中 -->      <bean id="exceptionResolver" class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver">          <property name="exceptionMappings">              <props>                  <!-- 遇到MaxUploadSizeExceededException异常时,自动跳转到/WEB-INF/jsp/error_fileupload.jsp页面 -->                  <prop key="org.springframework.web.multipart.MaxUploadSizeExceededException">error_fileupload</prop>              </props>          </property>      </bean>  </beans>  

0 0
原创粉丝点击