spring mvc 怎么大小上传文件控制?
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="maxUploadSize" value="123456" />
</>
但是用这个的话,超过value的话我的程序会跳错误页.是哪配置不对吗.
Spring API 中org.springframework.web.multipart.commons.CommonsMultipartResolver的resolveMultipart方法说明
public MultipartHttpServletRequest resolveMultipart(HttpServletRequest request) throws MultipartException
Throws:
MultipartException - if the servlet request is not multipart, or if implementation-specific problems are encountered (such as exceeding file size limits)
文件大小超出限制会抛出异常,应该是抛MaxUploadSizeExceededException
你可以在Controller中捕获一下,
@ExceptionHandler(MaxUploadSizeExceededException.class)
public String aaa(Model model) {
model.addAttribute("errorMsg", "上传的文件太大啦!");
return "maxUploadSizeExceeded";
}