PLAY FRAMEWORK JAVA:
I am trying to get the name of the URL that requested the controller function. For example , I have a routes as
GET /mypage controllers.Mypage.myfunction()
and I have another page that requests the same controller
GET /anotherpage controllers.Mypage.myfunction()
is there a way to find in controllers if the request is from /mypage
or from /anotherpage
?
Thanks
Say you visit example.com:9000/login?param=test
, then within your controller function:
public static Result login() {
// set to "/login" -- The URI path without query parameters.
String path = request().path();
// set to "/login?param=test" -- The full URI.
String uri = request().uri();
// set to "example.com:9000" -- The host name from the request, with port (if specified by the client).
String host = request().host();
...
}
you didn't mention language
In Scala you can get path in controller by
val path= request.path
or
val path=request.uri
i have tried this in play framework 2.2*
In Java
String path= request.path();
or
String path=request.url();
according to this link http://www.playframework.com/documentation/1.0.1/api/play/mvc/Http.Request.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With