链接损坏重定向到自己设计的404错误页面

本文介绍如何在web.xml中配置404错误页面的重定向,并提供了一个示例404页面的设计代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >



不存在的链接重定向到自己设计的404错误页面

在web.xml文件加入:

  1. <error-page>
  2. <error-code>403</error-code>
  3. <location>/error/403</location>
  4. </error-page>
  5. <error-page>
  6. <error-code>404</error-code>
  7. <location>/WEB-INF/error/404.jsp</location>
  8. </error-page>

自己设计的404错误页面:
  1. <%@pagelanguage="java"contentType="text/html;charset=utf-8"
  2. pageEncoding="utf-8"%>
  3. <!DOCTYPEhtmlPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
  4. <html>
  5. <head>
  6. <metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
  7. <title>页面找不到</title>
  8. <style>
  9. body{
  10. background-color:#f9f9f9;
  11. font-size:14px;
  12. }
  13. h1{
  14. font-size:20px;
  15. font-weight:bold;
  16. margin:0020px;
  17. padding:0;
  18. color:#444;
  19. }
  20. a{
  21. color:#428bca;
  22. text-decoration:none;
  23. }
  24. a:hover{
  25. text-decoration:underline;
  26. }
  27. .container{
  28. width:500px;
  29. margin:60pxauto;
  30. background:#fff;
  31. border:1pxsolid#ddd;
  32. }
  33. .content{
  34. padding:40px;
  35. }
  36. .message{
  37. margin-bottom:20px;
  38. color:#666;
  39. line-height:24px;
  40. }
  41. .actionsa{
  42. margin-right:20px;
  43. }
  44. </style>
  45. </head>
  46. <body>
  47. <divclass="container">
  48. <divclass="content">
  49. <h1>页面找不到</h1>
  50. <divclass="message">该页面已被删除,或地址错误。</div>
  51. <divclass="actions">
  52. <ahref="/index">返回首页</a>
  53. </div>
  54. </div>
  55. </div>
  56. </body>
  57. </html>

文件位置图:




不存在的链接重定向到自己设计的404错误页面

在web.xml文件加入:

  1. <error-page>
  2. <error-code>403</error-code>
  3. <location>/error/403</location>
  4. </error-page>
  5. <error-page>
  6. <error-code>404</error-code>
  7. <location>/WEB-INF/error/404.jsp</location>
  8. </error-page>

自己设计的404错误页面:
  1. <%@pagelanguage="java"contentType="text/html;charset=utf-8"
  2. pageEncoding="utf-8"%>
  3. <!DOCTYPEhtmlPUBLIC"-//W3C//DTDHTML4.01Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
  4. <html>
  5. <head>
  6. <metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
  7. <title>页面找不到</title>
  8. <style>
  9. body{
  10. background-color:#f9f9f9;
  11. font-size:14px;
  12. }
  13. h1{
  14. font-size:20px;
  15. font-weight:bold;
  16. margin:0020px;
  17. padding:0;
  18. color:#444;
  19. }
  20. a{
  21. color:#428bca;
  22. text-decoration:none;
  23. }
  24. a:hover{
  25. text-decoration:underline;
  26. }
  27. .container{
  28. width:500px;
  29. margin:60pxauto;
  30. background:#fff;
  31. border:1pxsolid#ddd;
  32. }
  33. .content{
  34. padding:40px;
  35. }
  36. .message{
  37. margin-bottom:20px;
  38. color:#666;
  39. line-height:24px;
  40. }
  41. .actionsa{
  42. margin-right:20px;
  43. }
  44. </style>
  45. </head>
  46. <body>
  47. <divclass="container">
  48. <divclass="content">
  49. <h1>页面找不到</h1>
  50. <divclass="message">该页面已被删除,或地址错误。</div>
  51. <divclass="actions">
  52. <ahref="/index">返回首页</a>
  53. </div>
  54. </div>
  55. </div>
  56. </body>
  57. </html>

文件位置图:



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值