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

How to add an error page in java

Release: 2019-12-14 15:37:43
Original
1763 people have browsed it

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>
Copy after login

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template