1、总览

2、代码

1)、pom.xml

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency> </dependencies>

2)、MyController.java

package com.ebc.controller;

import com.ebc.error.NotYetImplemented;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping; @Controller
public class MyController {
/**
* response status code=500,导航到5xx.html
*/
@RequestMapping("/")
public void handleRequest() {
throw new RuntimeException("test exception");
}
/**
* response status code=501,导航到5xx.html
*/
@RequestMapping("/app")
public void handleAppInfoRequest() throws NotYetImplemented {
throw new NotYetImplemented("The request page is not yet implemented");
} }

3)、ForbiddenException.java

package com.ebc.error;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus; @ResponseStatus(HttpStatus.FORBIDDEN)
public class ForbiddenException extends Exception {
public ForbiddenException(String message) {
super(message);
}
}

4)、NotYetImplemented.java

package com.ebc.error;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus; @ResponseStatus(HttpStatus.NOT_IMPLEMENTED)
public class NotYetImplemented extends Exception {
public NotYetImplemented(String message) {
super(message);
}
}

5)、5xx.html

<html>
<body>
<h1>My 5xx Error Page</h1>
<div id="locationDiv"></div>
<script>
document.getElementById("locationDiv").innerHTML = "Location: " + window.location.href;
</script>
</body>
</html>

6)、404.html

<html>
<body>
<h1>My 404 Error Page</h1>
<div id="locationDiv"></div>
<script>
document.getElementById("locationDiv").innerHTML = "Location: " + window.location.href;
</script></body>
</html>

3、执行

总结:

1、如果出现了非5xx、404返回码如403时,怎么办?使用error.jsp,并将其放在根下,如本例需放在static目录下。

2、5xx.html、404.html需放在error目录下。

springboot - 映射HTTP Response Status Codes 到 静态 HTML页面的更多相关文章

  1. springboot - 映射HTTP Response Status Codes 到 FreeMarker Error页面

    1.总览 2.代码 1).pom.xml 这里注意:springboot 2.2.0以后默认的freemarker文件后缀为:ftlh.本例用的是2.2.1,所以后缀为ftlh <depende ...

  2. springboot - 映射 HTTP Response Status Codes 到自定义 JSP Error 页面

    1.总览 2.代码 1).pom.xml <dependencies> <dependency> <groupId>org.springframework.boot ...

  3. HTTP状态码(HTTP Status codes)简介

    HTTP可能大家都熟悉,就是超文本传输协议.浏览器通过HTTP与WEB Server通讯(也有一些其它软件比如IM使用HTTP协议传递数据),把我们的请求(HTTP Request)传递给服务器,服务 ...

  4. SpringBoot学习笔记(3):静态资源处理

    SpringBoot学习笔记(3):静态资源处理 在web开发中,静态资源的访问是必不可少的,如:Html.图片.js.css 等资源的访问. Spring Boot 对静态资源访问提供了很好的支持, ...

  5. HTTP response status

    The status code is a 3-digit number: 1xx (Informational): Request received, server is continuing the ...

  6. C#、JAVA操作Hadoop(HDFS、Map/Reduce)真实过程概述。组件、源码下载。无法解决:Response status code does not indicate success: 500。

    一.Hadoop环境配置概述 三台虚拟机,操作系统为:Ubuntu 16.04. Hadoop版本:2.7.2 NameNode:192.168.72.132 DataNode:192.168.72. ...

  7. IIS SMTP status codes

    Here are the meaning of SMTP status codes. Status Code Description 211 System status, or system help ...

  8. HTTP常见返回代码(HTTP Status codes)的分类和含义

    HTTP错误主要分成三类:用户设备问题.Web服务器问题和连接问题.当客户端向Web服务器发送一个HTTP请求时,服务器都会返回一个响应代码.而这些响应代码主要分成五类. HTTP状态码中定义了5大类 ...

  9. returned a response status of 403 OR 409

    当我们使用jersy把图片上传到我们的图片服务器中[tomcat],我们可能会有以下的错误: returned a response status of 403 OR 409 403和409我都遇到过 ...

随机推荐

  1. Python学习第四课——基本数据类型一之int and str

    1.数字(int) - int() 方法 # 定义 a1=123 a2=456 #功能1:将字符串转换为数字 #例子1: a = " print(type(a)) # type()为查看类型 ...

  2. Keras入门——(2)卷积神经网络CNN

    前期准备工作参考:https://www.cnblogs.com/ratels/p/11144881.html 基于CNN算法利用Keras框架编写代码实现对Minst数据分类识别: from ker ...

  3. 二、Navicat、IDEA、nopad、eclipse、excle工具使用、问题、快捷键

    1.Navicat工具: 目的:本地数据库与远程数据库之间数据导入导出 步骤1:文件--新建oracle链接/mysql的连接 步骤2:工具-选项:将本地oracle的bin\oci.dll 的路径复 ...

  4. 如何在SecureCRT中上传文件到linux服务器上

    1.使用yum安装运行命令sudo yum install lrzsz(默认使没有安装运行命令的) 2.上传命令rz  下载命令sz  

  5. 剑指 offer 树的子结构

    题目描述: 输入两棵二叉树A,B,判断B是不是A的子结构.(ps:我们约定空树不是任意一个树的子结构). 第一遍没写出来错误点:认为首先应该找到pRoot1等于pRoot2的节点,但是递归就是自己在不 ...

  6. MongoDB分片技术原理和高可用集群配置方案

    一.Sharding分片技术 1.分片概述 当数据量比较大的时候,我们需要把数分片运行在不同的机器中,以降低CPU.内存和Io的压力,Sharding就是数据库分片技术. MongoDB分片技术类似M ...

  7. 转《Python爬虫学习系列教程》学习笔记

    http://www.cnblogs.com/xin-xin/p/4297852.html

  8. Codeforces Round #624 (Div. 3)(题解)

    Codeforces Round #624 (Div.3) 题目地址:https://codeforces.ml/contest/1311 B题:WeirdSort 题意:给出含有n个元素的数组a,和 ...

  9. $.ajax方法提交数组参数

    springmvc框架 var param = new Object(); var arr = new Array(); arr.push(1,2,3); param.ids=JSON.stringi ...

  10. docker中mysql数据库

    在docker中安装mysql数据库,直接上代码,pull 并run 补充20190809=============== 如果要挂载数据库实现数据持久化到本地的时候,会出现权限问题,这个原因是: 在执 ...