站长资讯网
最全最丰富的资讯网站

java添加错误页面的方法

java添加错误页面的方法

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>

赞(0)
分享到: 更多 (0)