如何在重定向到错误页面之前获取URL?

时间:2014-05-27 15:45:15

标签: spring spring-mvc

我一直在尝试获取用户在重定向到自定义错误页面之前错误输入的URL。

以下是我的内容,但我没有看到从wrong变量中获取request网址的方法

@RequestMapping(value = "/errors/404.html")
private String defaultPage(HttpServletRequest request,Exception e){
        request.getRequestURL().toString(); // this prints /error/404.html
        ...
        ...
}

我希望看到用户键入的www.example.com/home2之类的网址。但是,当我调试时,我可以看到以下

enter image description here

如何从请求中检索/home2

1 个答案:

答案 0 :(得分:0)

您可以使用RequestContextListener来获取绑定到当前Thread的请求。

检查这个答案:

What's the best way to get the current URL in Spring MVC?