How to add an error page in java:
1. Add the following configuration to 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. Create a new 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>
For more java knowledge, please pay attention to the java basic tutorial column.
The above is the detailed content of How to add an error page in java. For more information, please follow other related articles on the PHP Chinese website!