8

I got next problem with my application. I have to make my own 404 page and I'd like to write there "Page {requestedPage} not found" but I have no idea how to get this value.

I created Controller with RequestMapping

@RequestMapping("404")
public String handle404(Locale locale, Model model ,HttpServletResponse response, HttpServletRequest request){
    ...
}

and set this page in web.xml as 404 error page

<error-page>
    <error-code>404</error-code>
    <location>/404</location>
</error-page>

I found the same question on spring forum http://forum.springsource.org/showthread.php?87670-Knowing-the-requested-URL-during-a-404 but without answer

I looked for all HttpSerletRequest methods and fields but not found anything what can help.

Does anyone know how to do this?

SiMet
  • 614
  • 7
  • 18
  • 1
    Possible duplicate of [web.xml 404 redirect to servlet, how to get the original URI?](https://stackoverflow.com/questions/7465906/web-xml-404-redirect-to-servlet-how-to-get-the-original-uri) – Kalle Richter Feb 23 '19 at 15:45
  • This was already asked on stackoverflow: https://stackoverflow.com/questions/7465906/web-xml-404-redirect-to-servlet-how-to-get-the-original-uri I think the answer there is the one you are looking for. – Dirk Lachowski Dec 11 '12 at 16:38
  • 2
    Why not `String originalUri = request.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI);` as suggested at https://stackoverflow.com/questions/7465906/web-xml-404-redirect-to-servlet-how-to-get-the-original-uri? – Hasan Can Saral Nov 02 '19 at 13:07

0 Answers0