不存在的链接重定向到自己设计的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错误页面:
- <%@pagelanguage="java"contentType="text/html;charset=utf-8"
- pageEncoding="utf-8"%>
- <!DOCTYPEhtmlPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <metahttp-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:0020px;
- padding:0;
- color:#444;
- }
- a{
- color:#428bca;
- text-decoration:none;
- }
- a:hover{
- text-decoration:underline;
- }
- .container{
- width:500px;
- margin:60pxauto;
- background:#fff;
- border:1pxsolid#ddd;
- }
- .content{
- padding:40px;
- }
- .message{
- margin-bottom:20px;
- color:#666;
- line-height:24px;
- }
- .actionsa{
- margin-right:20px;
- }
- </style>
- </head>
- <body>
- <divclass="container">
- <divclass="content">
- <h1>页面找不到</h1>
- <divclass="message">该页面已被删除,或地址错误。</div>
- <divclass="actions">
- <ahref="/index">返回首页</a>
- </div>
- </div>
- </div>
- </body>
- </html>
文件位置图:
不存在的链接重定向到自己设计的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错误页面:
- <%@pagelanguage="java"contentType="text/html;charset=utf-8"
- pageEncoding="utf-8"%>
- <!DOCTYPEhtmlPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <metahttp-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:0020px;
- padding:0;
- color:#444;
- }
- a{
- color:#428bca;
- text-decoration:none;
- }
- a:hover{
- text-decoration:underline;
- }
- .container{
- width:500px;
- margin:60pxauto;
- background:#fff;
- border:1pxsolid#ddd;
- }
- .content{
- padding:40px;
- }
- .message{
- margin-bottom:20px;
- color:#666;
- line-height:24px;
- }
- .actionsa{
- margin-right:20px;
- }
- </style>
- </head>
- <body>
- <divclass="container">
- <divclass="content">
- <h1>页面找不到</h1>
- <divclass="message">该页面已被删除,或地址错误。</div>
- <divclass="actions">
- <ahref="/index">返回首页</a>
- </div>
- </div>
- </div>
- </body>
- </html>
文件位置图: