Tomcat发生错误时跳转到错误页面

注意 :5.0下操作需要删除掉注释语句,不然报错,原因未知

一、修改 tomcat 的配置文件

修改 tomcat 的配置文件,当页面发生错误时跳转到指定的页面,在 tomcat 中 web.xml 文件中添加如下内容:

<!-- 400错误 -->

<error-page>

<error-code>400</error-code>

<location>/error.html</location>

</error-page>

<!-- 404 页面不存在错误 -->

<error-page>

<error-code>404</error-code>

<location>/error.html</location>

</error-page>

<!-- 500 服务器内部错误 -->

<error-page>

<error-code>500</error-code>

<location>/error.html</location>

</error-page>

<!-- java.lang.Exception异常错误,依据这个标记可定义多个类似错误提示 -->

<error-page>

<exception-type>java.lang.Exception</exception-type>

<location>/error.html</location>

</error-page>

<!-- java.lang.NullPointerException异常错误,依据这个标记可定义多个类似错误提示 -->

<error-page>

<exception-type>java.lang.NullPointerException</exception-type>

<location>/error.html</location>

</error-page>

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

二、编写 error.html 界面

error.html 界面需要放在 webapps 的 ROOT 目录中,结构如下:

404文件夹内容

error.html

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml"><head>

<title>网页访问不了</title>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<link rel="stylesheet" type="text/css" href="404/error_all.css?t=201303212934">

</head>

<body class="error-404">

<div id="doc_main">

<section class="bd clearfix">

<div class="module-error">

<div class="error-main clearfix">

<div class="label"></div>

<div class="info">

<h3 class="title">啊哦,你所访问的页面不存在了,可能是炸了</h3>

<div class="reason">

<p>可能的原因:</p>

<p>1.手抖打错了。</p>

<p>2.链接过了保质期。</p>

</div>

<div class="oper">

<p><a href="javascript:history.go(-1);">返回上一级页面></a></p>

</div>

</div>

</div>

</div>

</section>

</div>

</body></html>

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

error_all.css

body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, code, form, textarea, select, optgroup, option, fieldset, legend, p, blockquote, th, td {

margin:0;

padding:0

}

fieldset, img {

border:0

}

ul, li, ol {

list-style:none

}

h1, h2, h3, h4, h5, h6 {

font-size:100%

}

legend {

color:#000

}

input, button, textarea, select, optgroup, option {

font-family:inherit;

font-size:inherit;

font-style:inherit;

font-weight:inherit

}

input, button, select {

margin:0;

*font-size:100%;

line-height:1.2

}

a img, img {

-ms-interpolation-mode:bicubic

}

body {

background:#FFF

}

a {

color:#06c;

text-decoration:none

}

a:hover, a:active, a:focus {

color:#06c;

text-decoration:underline

}

table {

border-collapse:collapse;

border-spacing:0

}

header, aside, section {

display:block

}

body, button, input, select, textarea {

font:12px/1.5 tahoma, arial, "微软雅黑";

color:#666

}

.center {

text-align:center

}

.clear:after, .clearfix:after {

content:".";

display:block;

clear:both;

visibility:hidden;

font-size:0;

height:0;

line-height:0

}

.clear, .clearfix {

zoom:1

}

.b-panel {

position:absolute

}

.b-fr {

float:right

}

.b-fl {

float:left

}

.error-404 {

background-color:#EDEDF0

}

.module-error {

margin-top:182px

}

.module-error .error-main {

margin:0 auto;

width:420px

}

.module-error .label {

float:left;

width:160px;

height:151px;

background:url('error.png') 0 0 no-repeat

}

.module-error .info {

margin-left:182px;

line-height:1.8

}

.module-error .title {

color:#666;

font-size:14px

}

.module-error .reason {

margin:8px 0 18px 0;

color:#666

}

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

error.png

---------------------

作者:qq_35959573

来源:CSDN

原文:https://blog.csdn.net/qq_35959573/article/details/80597164

版权声明:本文为博主原创文章,转载请附上博文链接!

Tomcat发生错误时跳转到错误页面
一、修改 tomcat 的配置文件修改 tomcat 的配置文件,当页面发生错误时跳转到指定的页面,在 tomcat 中 web.xml 文件中添加如下内容:
<!-- 400错误 -->  <error-page>      <error-code>400</error-code>      <location>/error.html</location>  </error-page>  <!-- 404 页面不存在错误 -->  <error-page>      <error-code>404</error-code>      <location>/error.html</location>  </error-page>  <!-- 500 服务器内部错误 -->  <error-page>      <error-code>500</error-code>      <location>/error.html</location>  </error-page>  <!-- java.lang.Exception异常错误,依据这个标记可定义多个类似错误提示 -->  <error-page>      <exception-type>java.lang.Exception</exception-type>      <location>/error.html</location>  </error-page>  <!-- java.lang.NullPointerException异常错误,依据这个标记可定义多个类似错误提示 -->  <error-page>      <exception-type>java.lang.NullPointerException</exception-type>      <location>/error.html</location>  </error-page>12345678910111213141516171819202122232425二、编写 error.html 界面error.html 界面需要放在 webapps 的 ROOT 目录中,结构如下:
 404文件夹内容

error.html
<!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head><title>网页访问不了</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><link rel="stylesheet" type="text/css" href="404/error_all.css?t=201303212934"></head><body class="error-404"><div id="doc_main">
    <section class="bd clearfix">        <div class="module-error">            <div class="error-main clearfix">                <div class="label"></div>                <div class="info">                    <h3 class="title">啊哦,你所访问的页面不存在了,可能是炸了</h3>                    <div class="reason">                        <p>可能的原因:</p>                        <p>1.手抖打错了。</p>                        <p>2.链接过了保质期。</p>                    </div>                    <div class="oper">                        <p><a href="javascript:history.go(-1);">返回上一级页面></a></p>                    </div>                </div>            </div>        </div>    </section></div>
</body></html>12345678910111213141516171819202122232425262728293031error_all.css
body, div, dl, dt, dd, ul, ol, li, h1, h2, h3, h4, h5, h6, pre, code, form, textarea, select, optgroup, option, fieldset, legend, p, blockquote, th, td {    margin:0;    padding:0}fieldset, img {    border:0}ul, li, ol {    list-style:none}h1, h2, h3, h4, h5, h6 {    font-size:100%}legend {    color:#000}input, button, textarea, select, optgroup, option {    font-family:inherit;    font-size:inherit;    font-style:inherit;    font-weight:inherit}input, button, select {    margin:0;*font-size:100%;    line-height:1.2}a img, img {    -ms-interpolation-mode:bicubic}body {    background:#FFF}a {    color:#06c;    text-decoration:none}a:hover, a:active, a:focus {    color:#06c;    text-decoration:underline}table {    border-collapse:collapse;    border-spacing:0}header, aside, section {    display:block}body, button, input, select, textarea {    font:12px/1.5 tahoma, arial, "微软雅黑";    color:#666}.center {    text-align:center}.clear:after, .clearfix:after {    content:".";    display:block;    clear:both;    visibility:hidden;    font-size:0;    height:0;    line-height:0}.clear, .clearfix {    zoom:1}.b-panel {    position:absolute}.b-fr {    float:right}.b-fl {    float:left}.error-404 {    background-color:#EDEDF0}.module-error {    margin-top:182px}.module-error .error-main {    margin:0 auto;    width:420px}.module-error .label {    float:left;    width:160px;    height:151px;    background:url('error.png') 0 0 no-repeat}.module-error .info {    margin-left:182px;    line-height:1.8}.module-error .title {    color:#666;    font-size:14px}.module-error .reason {    margin:8px 0 18px 0;    color:#666}123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105error.png 
--------------------- 作者:qq_35959573 来源:CSDN 原文:https://blog.csdn.net/qq_35959573/article/details/80597164 版权声明:本文为博主原创文章,转载请附上博文链接!

Tomcat 配置错误界面的更多相关文章

  1. Tomcat配置错误导致Quartz执行两次问题

    以下基于tomcat服务器 我们通常将域名映射到指定服务器的端口上,以通过域名直接访问服务,如http://www.abc.com域名已绑定到本机的80端口,项目名wechat,则直接访问http:/ ...

  2. Spring Boot2.2.X中Tomcat配置 错误定制

    1: Tomcat定制 EmbeddedServletContainerCustomizer 已久废弃 按照下面的方式来处理 通过的类的配置 @Component public class Tomca ...

  3. '[linux下tomcat 配置

    tomcat目录结构 bin ——Tomcat执行脚本目录 conf ——Tomcat配置文件 lib ——Tomcat运行需要的库文件(JARS) logs ——Tomcat执行时的LOG文件 te ...

  4. Tomcat启动报错org.springframework.web.context.ContextLoaderListener类配置错误——SHH框架

    SHH框架工程,Tomcat启动报错org.springframework.web.context.ContextLoaderListener类配置错误 1.查看配置文件web.xml中是否配置.or ...

  5. tomcat配置根目录访问后,部署后第一次访问会出现tomcat的默认界面而非项目首页

    tomcat配置根目录访问后,部署后第一次访问会出现tomcat的默认界面而非项目首页,而重启后会正常,这个原因是因为在配置文件中有如下配置,造成项目加载两次 <Host name=" ...

  6. Tomcat配置全攻略

    tomcat的的下载地址http://www.apache.org/dist/jakarta/tomcat-4/ 1.安装jdk,详细操作请参考本站windows 2k和redhat 8.0下java ...

  7. Linux配置tomcat (centos配置java环境 tomcat配置篇 总结三)

    ♣下载安装tomcat7 ♣设置启动和关闭 ♣设置用户名和密码 ♣发布java web项目 声明:这篇教程是建立在前两篇教程的基础上的,所以,还没安装工具和jdk,可以先看这个系列的前面两篇(去到文末 ...

  8. tomcat配置调优与安全总结

    http://vekergu.blog.51cto.com/9966832/1672931 tomcat配置调优与安全总结 作为运维,避免不了与tomcat打交道,然而作者发现网络上关于tomcat配 ...

  9. (转)Tomcat配置调优与安全总结

    tomcat配置调优与安全总结 作为运维,避免不了与tomcat打交道,然而作者发现网络上关于tomcat配置和调优安全的文章非常散,通过参考各位大神的相关技术文档,根据作者对tomcat的运维经验, ...

随机推荐

  1. MySQL中常见函数

    一.日期函数 1.NOW()   返回当前日期和时间 mysql> SELECT NOW(); +---------------------+ | NOW() | +-------------- ...

  2. 微软Cortana可以帮助任何人解锁您的Windows 10系统

    Cortana是微软在每个版本的Windows10中都内置的基于人工智能的智能助手,可以帮助攻击者解锁你的系统密码. 在周二发布的最新补丁中,微软推出了一项重要更新,以解决Cortana中容易被利用的 ...

  3. webRTC脱坑笔记(一)— 初识webRTC

    webRTC概述 WebRTC--- `Web browsers with Real-Time Communications (RTC)` WebRTC是一个开源项目,可以在`Web`和本机应用程序中 ...

  4. pipelines和重定向命令

    pipelines: command1 | command2 例如,ls -l /usr/bin | less,将输出结果作为 less 命令的输入结果,在standard output 中显示出来. ...

  5. 线性规划(Simplex单纯形)与对偶问题

    线性规划 首先一般所有的线性规划问题我们都可以转换成如下标准型: 但是我们可以发现上面都是不等式,而我们计算中更希望是等式,所以我们引入这个新的概念:松弛型: 很显然我们最后要求是所有的约束左边的变量 ...

  6. 2019牛客多校第六场 B - Shorten IPv6 Address 模拟

    B - Shorten IPv6 Address 题意 给你\(128\)位的二进制,转换为十六进制. 每\(4\)位十六进制分为\(1\)组,每两组用一个\(":"\)分开. 每 ...

  7. window安装oracle和创建数据库

    原文地址: https://www.cnblogs.com/hoobey/p/6010804.html  #11g安装 https://www.cnblogs.com/qq1272850043/p/6 ...

  8. 微信网页开发调用微信jssdk接口遇到的坑以及最终解决方法 (持续更新)

    1.微信网页开发调用jssdk时报permission denied 大致是两个原因 (1)首先注册时未将你所调用的接口名字添加至jsApiList (2)第二个就是你的这个公众号没有权限使用这个ap ...

  9. python的列表 元组 字典

    列表和元组都是序列,是数据元素的集合,数据元素可以是数值.字符串,布尔值.对象等. 一.列表:用方括号定义[] 空列表 names = [] 带值的列表 names = ["bill&quo ...

  10. 算法中时间复杂度概括——o(1)、o(n)、o(logn)、o(nlogn)

    在描述算法复杂度时,经常用到 o(1), o(n), o(logn), o(nlogn) 来表示对应算法的时间复杂度, 这里进行归纳一下它们代表的含义:这是算法的时空复杂度的表示.不仅仅用于表示时间复 ...