Springmvc 上传文件过大会导致直接出现50错误页面
springmvc.xml 配置
<!-- 件上传视图解析器,它的名字必须为multipartResolver -->
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="10485760"/><!-- 10M -->
<!--resolveLazily属性启用是为了推迟文件解析,以便在UploadAction 中捕获文件大小异常-->
<property name="resolveLazily" value="true"/>
</bean>
用 @ExceptionHandler 可以捕获到springMVC抛出的文件过大的异常,
@ExceptionHandler(MaxUploadSizeExceededException.class)
public String handleException(MaxUploadSizeExceededException ex) throws Exception {
return "redirect:/fileUpload.jsp"; // return "fileUpload"; }