2

I have the following controller:

@Controller
public class MyErrorController implements ErrorController {

    @RequestMapping("/error")
    public String handleError(HttpServletRequest request, Model model) {

        Object url = request.getRequestURL()
        model.addAttribute("url", url)
        return "404";
    }

}

However, the above url always gives me the url "/error", even if the user has went to the page "http://mywebsite.com/does-not-exist". How would I retrieve the url as entered in by the user before generating the error page?

David542
  • 104,438
  • 178
  • 489
  • 842

1 Answers1

4

You should be able to pull it from request.getAttribute(RequestDispatcher.FORWARD_REQUEST_URI)

This thread has further information : web.xml 404 redirect to servlet, how to get the original URI?

Rich Ackroyd
  • 117
  • 6