播放框架JAVA:
我正在尝试获取请求控制器功能的URL的名称。例如 , 我有一条路线
GET /mypage controllers.Mypage.myfunction()
我有另一个页面请求同一个控制器
GET /anotherpage controllers.Mypage.myfunction()
如果请求来自/mypage
或来自/anotherpage
,是否可以在控制器中查找?
由于
答案 0 :(得分:21)
假设您访问example.com:9000/login?param=test
,然后在控制器功能中访问:
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();
...
}
答案 1 :(得分:4)
你没有提到语言
在Scala中,您可以通过
获取控制器中的路径val path= request.path
或
val path=request.uri
我在play framework 2.2 *
中试过这个在Java中
String path= request.path();
或
String path=request.url();
根据此链接http://www.playframework.com/documentation/1.0.1/api/play/mvc/Http.Request.html