Tomcat 配置错误界面

2023-11-02

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 版权声明:本文为博主原创文章,转载请附上博文链接!

转载于:https://www.cnblogs.com/pegasus827/p/10419455.html

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

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

  • 使用 java 按电子邮件发送日历邀请

    我正在尝试使用 java 发送每封电子邮件的日历邀请 收件人收到电子邮件 但不会显示接受或拒绝的邀请 而是将该事件自动添加到他的日历中 我正在使用 ical4j jar 构建活动 邀请 private Calendar getInvite
  • 使用 Guava 联合两个 ImmutableEnumSets

    我想联合两个ImmutableEnumSets来自番石榴 这是我的尝试 public final class OurColors public enum Colors RED GREEN BLUE YELLOW PINK BLACK pub
  • 将数字限制为段的最优雅的方法是什么?

    比方说x a and b是数字 我需要限制x到段的边界 a b 换句话说 我需要一个钳位功能 https math stackexchange com q 1336636 clamp x max a min x b 有人能想出一个更易读的版
  • 如何按值删除数组中的多个项目?

    我正在尝试做一个removeAll 函数 它将删除具有该特定值 而不是索引 的数组的所有元素 当我们对循环进行任何更改时 棘手的部分就出现了 索引往往会移动 使其很难像我们想要的那样工作 并且每次更改时都重新启动循环 这在大数组上效率非常低
  • 您网站上的自定义 jQuery 脚本有多少行代码?多少才算是太多呢?

    对于我们的网站 我使用了大量 jQuery 现在我正在查看基础库顶部的 340 行 jQuery 代码 多少是太多了 我将添加更多内容 我什么时候开始尝试压缩代码并最终转向 OOP 行数并不意味着什么 重要的是你实际上在做什么 您可能拥有
  • 如何在java中使jpeg无损?

    有没有人可以告诉我如何使用编写 jpeg 文件losslessjava中的压缩 我使用下面的代码读取字节来编辑字节 WritableRaster raster image getRaster DataBufferByte buffer Da
  • 两个日期之间间隔 15 分钟 javascript

    问题 我需要将两个日期 时间戳之间的所有 15 分钟时隙 日期格式 2016 08 10 16 00 00 创建为 HH mm 格式的数组 其中分钟限制为 00 15 30 45 示例 中午 12 30 到下午 2 30 将 gt 12 3
  • 具有多种值类型的 Java 枚举

    基本上我所做的是为国家编写一个枚举 我希望不仅能够像国家一样访问它们 而且还能够访问它们的缩写以及它们是否是原始殖民地 public enum States MASSACHUSETTS Massachusetts MA true MICHI
  • backbone.js:视图中影响集合中不同模型的按钮

    我刚刚开始使用backbone js 到目前为止 我真的很喜欢它 我有这样的事情 ModelA ModelB ViewA ViewB ModelA 持有 ModelB 的集合 如何使用按钮构建模型 B 的视图 单击该按钮会更改集合中下一个
  • jmap - 组织和堆操作会给 jvm 带来开销吗?

    正如标题所述 需要多少开销jmap histo and jmap heap分别带到jvm 如果一个内存敏感的 Java 进程处于OutOfMemory 例如 大约 96 的堆已满 并且无法通过 full gc 清除 其中一项操作是否有可能将
  • Apache Commons CLI:替代已弃用的 OptionBuilder?

    IntelliJ 显示此示例代码中不推荐使用 OptionBuilderhttp commons apache org proper commons cli usage html http commons apache org proper
  • 在 AKKA 中,对主管调用 shutdown 是否会停止其监督的所有参与者?

    假设我有一位主管连接了 2 位演员 当我的应用程序关闭时 我想优雅地关闭这些参与者 调用supervisor shutdown 是否会停止所有参与者 还是我仍然需要手动停止我的参与者 gracias 阻止主管 https github co
  • 将 RSA 密钥从 BigIntegers 转换为SubjectPublicKeyInfo 形式

    WARNING 最初的问题是关于 PKCS 1 编码密钥 而问题中的实际示例需要SubjectPublicKeyInfo X 509 编码密钥 我目前正致力于在 java 中从头开始实现 RSA 算法 特别是密钥生成方面 现在我的代码可以给
  • 重写Object类的finalize()方法有什么用?

    据我所知 在java中如果我们想手动调用垃圾收集器 我们可以执行System gc 1 我们在重写的finalize 方法中做了哪些操作 2 如果我们想手动调用JVM垃圾收集器 是否需要重写finalize 方法 我们在重写的 Finali
  • 从一个文本文件中获取数据并将其移动到新的文本文件

    我有一个文件 里面有数据 在我的主要方法中 我读入文件并关闭文件 我调用另一种方法 在原始文件的同一文件夹内创建一个新文件 所以现在我有两个文件 原始文件和通过我调用的方法生成的文件 我需要另一种方法 从原始文件中获取数据并将其写入创建的新
  • 将 javascript 变量作为参数传递给 @url.Action()

    是否可以将javascript变量作为参数传递给 url Action 因为据我所知可能存在服务器和客户端问题 我的要求是我必须根据过滤器下载文件 并进行ajax调用不适用于下载文件 所以我对 url Action 进行了编码 但无法实现这
  • Java中获取集合的幂集

    的幂集为 1 2 3 is 2 3 2 3 1 2 1 3 1 2 3 1 假设我有一个Set在爪哇中 Set
  • 将日期参数传递给对 MVC 操作的 ajax 调用的安全方法

    我有一个 MVC 操作 它的参数之一是DateTime如果我通过 17 07 2012 它会抛出一个异常 指出参数为空但不能有空值 但如果我通过01 07 2012它被解析为Jan 07 2012 我将日期传递给 ajax 调用DD MM
  • 允许 iframe 跨域链接到目标父框架

    我有 2 个域 域 1 上的一个页面使用 iframe 加载域 2 中的内容 如何允许来自domain2 iframe 内 的链接在domain1 的完整父框架中打开 我一直在关注IE和w3c的新沙箱属性 http www w3 org T
  • Java 推断泛型类型

    我正在寻找类似的推断捕获泛型类型的概念 类似于以下方法片段 但不是捕获泛型类型的类 public

随机推荐