全局异常跳转页面

package com.zjqy.qbcs.security.error;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

/**
 * 全局异常跳转页面
 */
@ControllerAdvice
public class IMoocExceptionHandler {

    public static final String IMOOC_ERROR_VIEW = "error";

    @ExceptionHandler(value = Exception.class)
    public Object errorHandler(HttpServletRequest reqest,
                               HttpServletResponse response, Exception e) throws Exception {

        e.printStackTrace();

        ModelAndView mav = new ModelAndView();
        mav.addObject("exception", e);
        mav.addObject("url", reqest.getRequestURL());
        mav.setViewName(IMOOC_ERROR_VIEW);
        return mav;
    }

}
<!DOCTYPE html>
<html lang="zh-CN" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">

<head>
    <meta charset="UTF-8">
    <title>首页</title>
</head>

<body>
<h1 style="color: red">发生错误:</h1>
<div th:text="${url}"></div>
<div th:text="${exception.message}"></div>

就算是系统报错我也要说只是网络有问题! 404

"\t\t *                             _ooOoo_\n" +
"\t\t *                            o8888888o\n" +
"\t\t *                            88\" . \"88\n" +
"\t\t *                            (| -_- |)\n" +
"\t\t *                            O\\  =  /O\n" +
"\t\t *                         ____/`---'\\____\n" +
"\t\t *                       .'  \\\\|     |//  `.\n" +
"\t\t *                      /  \\\\|||  :  |||//  \\\n" +
"\t\t *                     /  _||||| -:- |||||-  \\\n" +
"\t\t *                     |   | \\\\\\  -  /// |   |\n" +
"\t\t *                     | \\_|  ''\\---/''  |   |\n" +
"\t\t *                     \\  .-\\__  `-`  ___/-. /\n" +
"\t\t *                   ___`. .'  /--.--\\  `. . __\n" +
"\t\t *                .\"\" '<  `.___\\_<|>_/___.'  >'\"\".\n" +
"\t\t *               | | :  `- \\`.;`\\ _ /`;.`/ - ` : | |\n" +
"\t\t *               \\  \\ `-.   \\_ __\\ /__ _/   .-` /  /\n" +
"\t\t *          ======`-.____`-.___\\_____/___.-`____.-'======\n" +
"\t\t *                             `=---='\n" +
"\t\t *          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
"\t\t *                     佛祖保佑        永无BUG\n" +
"\t\t *            佛曰:\n" +
"\t\t *                   写字楼里写字间,写字间里程序员;\n" +
"\t\t *                   程序人员写程序,又拿程序换酒钱。\n" +
"\t\t *                   酒醒只在网上坐,酒醉还来网下眠;\n" +
"\t\t *                   酒醉酒醒日复日,网上网下年复年。\n" +
"\t\t *                   但愿老死电脑间,不愿鞠躬老板前;\n" +
"\t\t *                   奔驰宝马贵者趣,公交自行程序员。\n" +
"\t\t *                   别人笑我忒疯癫,我笑自己命太贱;\n" +
"\t\t *                   不见满街漂亮妹,哪个归得程序员?"
</body>
</html>

 

写一个html,让报错,都来这里

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值