JAVA记录-添加错误页面友好提示

1.web.xml加入以下配置

 <error-page>
    <error-code>404</error-code>
    <location>/WEB-INF/include/error.jsp</location>
    </error-page>
    <error-page>
    <error-code>500</error-code>
    <location>/WEB-INF/include/error.jsp</location>
    </error-page>
    <error-page>
    <error-code>java.lang.Exception</error-code>
    <location>/WEB-INF/include/error.jsp</location>
    </error-page>

2.新建error.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" isErrorPage="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Error</title>
</head>
<body>
<%
  response.setStatus(200);
%>
很抱歉,您请求的页面不存在......
</body>
</html>

3.测试

http://ip:端口号/项目名/index

posted @ 2017-10-19 10:02  信方  阅读(870)  评论(0编辑  收藏  举报