不存在的链接重定向到自己设计的404错误页面
在web.xml文件加入:
- <error-page>
- <error-code>403</error-code>
- <location>/error/403</location>
- </error-page>
- <error-page>
- <error-code>404</error-code>
- <location>/WEB-INF/error/404.jsp</location>
- </error-page>
自己设计的404错误页面:
- <%@ page language="java" contentType="text/html; charset=utf-8"
- pageEncoding="utf-8"%>
- <!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>页面找不到</title>
- <style>
- body {
- background-color: #f9f9f9;
- font-size: 14px;
- }
- h1 {
- font-size: 20px;
- font-weight: bold;
- margin: 0 0 20px;
- padding: 0;
- color: #444;
- }
- a {
- color: #428bca;
- text-decoration: none;
- }
- a:hover {
- text-decoration: underline;
- }
- .container {
- width: 500px;
- margin: 60px auto;
- background: #fff;
- border: 1px solid #ddd;
- }
- .content {
- padding: 40px;
- }
- .message {
- margin-bottom: 20px;
- color: #666;
- line-height: 24px;
- }
- .actions a {
- margin-right: 20px;
- }
- </style>
- </head>
- <body>
- <div class="container">
- <div class="content">
- <h1>页面找不到</h1>
- <div class="message">该页面已被删除,或地址错误。</div>
- <div class="actions">
- <a href="/index">返回首页</a>
- </div>
- </div>
- </div>
- </body>
- </html>
文件位置图: