Home  >  Article  >  Java  >  How to add an error page in java

How to add an error page in java

尚
Original
2019-12-14 15:37:431705browse

How to add an error page in java

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn