Html JSP/Servlet HTTP 404错误处理

Html JSP/Servlet HTTP 404错误处理,html,jsp,http-status-code-404,Html,Jsp,Http Status Code 404,我想在我的web应用程序中处理HTML404错误 我可以这样写: <error-page> <error-code>404</error-code> <location>/view/error404.jsp</location> </error-page> 404 /view/error404.jsp 这非常有效,但我想记录用户键入的每个无效URL。 当我在error404.jsp中使用scriptl

我想在我的web应用程序中处理HTML404错误

我可以这样写:

    <error-page>
  <error-code>404</error-code>
  <location>/view/error404.jsp</location>
 </error-page>

404
/view/error404.jsp
这非常有效,但我想记录用户键入的每个无效URL。 当我在error404.jsp中使用scriptlet时,如下所示:

 <% 
     System.out.println(request.getRequestURL());
   %>

我总是得到:,因为用户将从无效的URL转发到我的error404.jsp


如何获取无效的URL?或者我应该如何编写一个servlet来捕获其他servlet未显式处理的所有请求?

它存储为请求属性,键为javax.servlet.forward.request\u uri:

<p>URL: ${requestScope['javax.servlet.forward.request_uri']}</p>
URL:${requestScope['javax.servlet.forward.request\u uri']}

或者,如果您仍然使用传统的JSP 1.x,它在十多年前就已经升级过了,那么请执行以下操作:

<p>URL: <%= request.getAttribute("javax.servlet.forward.request_uri"); %></p>
URL: