JSP && Servlet | 错误统一处理

对404错误和500错误处理:

在WebContent文件下新建404.jsp 和 500.jsp 显示错误时弹出的信息

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>404</title>
</head>
<body>
  
  找不到请求路径!
 
</body>
</html>

  

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>500</title>
</head>
<body>
 内部错误!
 
</body>
</html>

  

在web.xml里配置路径:

 <error-page>
    <error-code>500</error-code>
    <location>/500.jsp</location>
  </error-page>
  <error-page>
    <error-code>404</error-code>
    <location>/404.jsp</location>
  </error-page>

重新启动路径即可!

猜你喜欢

转载自www.cnblogs.com/jj81/p/10163659.html