为了给浏览者一个友好的错误提示页面,我们可以自定义错误页面:
步骤如下:
一、打开WEB-INF文件夹下web.xml文件;
二、在里面新增:
<!-- 404 页面不存在错误 -->
<error-page>
<error-code>404</error-code>
<location>/errorpage404.htm</location>
</error-page>
<!-- 500 服务器内部错误 -->
<error-page>
<error-code>500</error-code>
<location>/errorpage500.htm</location>
</error-page>
<!-- java.lang.Exception异常错误,依据这个标记可定义多个类似错误提示 -->
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/exception.htm</location>
</error-page>
三、保存web.xml文件,重启应用服务器。
步骤如下:
一、打开WEB-INF文件夹下web.xml文件;
二、在里面新增:
<!-- 404 页面不存在错误 -->
<error-page>
<error-code>404</error-code>
<location>/errorpage404.htm</location>
</error-page>
<!-- 500 服务器内部错误 -->
<error-page>
<error-code>500</error-code>
<location>/errorpage500.htm</location>
</error-page>
<!-- java.lang.Exception异常错误,依据这个标记可定义多个类似错误提示 -->
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/exception.htm</location>
</error-page>
三、保存web.xml文件,重启应用服务器。