denghui-study

1.欢迎页面

每次启动服务器的时候,都会执行webapp下的index.jsp,我们也可以自己设置自己想要启动服务器时执行的资源。

在webapp下新建一个hello.html文件:

<head>
    <meta charset="UTF-8">
    <title>欢迎页面</title>
</head>
<body>
您好,欢迎您的登陆!
</body>
</html>

在web.xml中配置:

<web-app>
<!--    设置欢迎页面-->
    <welcome-file-list>
<!--     注意:路径不需要/开头-->
        <welcome-file>hello.html</welcome-file>
    </welcome-file-list>
</web-app>

启动服务器:

资源不仅仅可以是html,还可以是jsp,sevrlet等等。。。都不需要/开头

那为什么我们没有配置的时候,服务器会执行index.jsp文件呢?

那是因为,虽然我们没有配置,但是Tomcat已经帮我们配置了,在Tomcat的conf文件夹下的web.xml文件中,可以打开文件看一看:在文件最后

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

Tomcat中的配置是全局配置,当我们自己在项目中局部配置之后,全局配置就不起作用了。可以修改全局配置。

2.错误页面

当发生404错误或者是500错误的时候,页面会出现一些错误提示:

但是这对用户来说肯定就是很懵逼的,所以我们可以指定一些发生错误时显示的页面。

先简单的给两个页面:webapp下

404.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>404</title>
</head>
<body>
您要访问的资源飞了...
</body>
</html>

500.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>500</title>
</head>
<body>
服务器内部错误,请稍后再试!
</body>
</html>

在web.xml中配置:

<!--错误页面-->
<error-page>
    <error-code>404</error-code>
    <location>/404.html</location>
</error-page>

<error-page>
    <error-code>500</error-code>
    <location>/500.html</location>
</error-page>

结果:

404:

500:

不仅仅可以是html,也可以是jsp,servlet等。。路径需要/开头。

分类:

技术点:

相关文章:

  • 2022-02-25
  • 2021-09-05
  • 2021-09-12
  • 2022-01-20
  • 2022-12-23
  • 2021-12-24
  • 2022-01-07
  • 2021-10-01
猜你喜欢
  • 2021-10-09
  • 2021-10-21
  • 2021-11-01
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
  • 2021-07-16
相关资源
相似解决方案