您的位置:首页 > 运维架构 > Tomcat

Tomcat 404/500 自定义404/500错误页面

2017-05-12 15:28 579 查看
有时服务器意外出错了,Tomcat自带的错误页面很”“,我们可以自定义错误页面给客户友好的提示。

1.方法很简单,在web.xml中做如下配置

<error-page>
<error-code>500</error-code>
<location>/error.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/error.jsp</location>
</error-page>


2.然后在webapp或WebRoot写一个error.jsp即可,

<%@ page contentType="text/html; charset=UTF-8" isErrorPage="true" %>
<%@ page import="java.io.*" %>
<html>
<body>
<h2>Oops! Exceptions occurred</h2>
<%
response.getWriter().println("Exception: " + exception);
%>
</body>
</html>


注意:只有isErrorPage=”true”才能调用exception
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息