在文件上传的基础上的改动
目录
web.xml修改文件上传大小制造异常
error.jsp 错误页面
<%--
Created by IntelliJ IDEA.
User: 管 理 员
Date: 2021年11月07日 0007
Time: 18:00:18
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>error.jsp</title>
</head>
<body>
<h1>出错了</h1>
<div>${error}</div>
</body>
</html>
Exceptionhandler.java 配置全局异常的类
package org.javaboy.fileupload.exception;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;
/**
* @author 邓雪松 (づ ̄ 3 ̄)づ)
* @create 2021-11-07-18-02
* 配置全局异常的类
*/
@ControllerAdvice
public class ExceptionHandle {
@ExceptionHandler(Exception.class)
public ModelAndView fileuploadSizeLimit(Exception e){
ModelAndView mv = new ModelAndView("error");
mv.addObject("error",e.getMessage());
return mv;
}
}
运行结果
结束 ~