javaurlplayframeworkrequestplayframework-2.3

(Play Framework 2.3.x) How to get the previous url?


In play Framework, how can I get the URL the user came from in a controller?

I've tried request.url, but that isn't working.


Solution

  • Previous url will come with the http headers under the referer key. In JAVA you can get it using:

    String refererUrl = request().getHeader("referer");
    

    and if you doing it in Scala:

    val refererUrl = request.headers("referer")