Get Referer URL in Spring MVC

后端 未结 2 1775
星月不相逢
星月不相逢 2021-02-02 07:36

How can I get the referer URL in Spring MVC Controller?

2条回答
  •  感情败类
    2021-02-02 08:06

    It's available as HTTP request header with the name referer (yes, with the misspelling which should have been referrer).

    String referrer = request.getHeader("referer");
    // ...
    

    Here the request is the HttpServletRequest which is available in Spring beans in several ways, among others by an @AutoWired.

    Please keep in mind that this is a client-controlled value which can easily be spoofed/omitted by the client.

提交回复
热议问题