Capturing exceptions with tomcat and servlet

I have setcat tomcat to catch all my exceptions and pass them to the servlet with the following in web.xml.

<servlet-mapping> <servlet-name>exception</servlet-name> <url-pattern>/exception</url-pattern> </servlet-mapping> <error-page> <exception-type>java.lang.Exception</exception-type> <location>/exception</location> </error-page> 

This works fine, and I have a servlet logging some information and forwarding to jsp. However, I want to register the URI that caused the exception to be thrown, and when I call request.getRequestURI (), I get / exception, which is my servlet path that handles the exception. How can I get the source URI that caused the exception?

+4
source share
1 answer

You can get the source uri with

 request.getAttribute("javax.servlet.forward.request_uri") 
+2
source

Source: https://habr.com/ru/post/1277619/


All Articles