簡體   English   中英

Play Framework 2.2:獲取請求頁面的URL

[英]Play Framework 2.2 : Get URL of the requesting page

播放框架JAVA:

我試圖獲取請求控制器功能的URL的名稱。 例如,我有一條路線

GET /mypage controllers.Mypage.myfunction()

我有另一個請求相同控制器的頁面

GET /anotherpage controllers.Mypage.myfunction()

如果請求來自/mypage/anotherpage有沒有辦法在控制器中找到?

謝謝

假設您訪問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(); 

    ...
}

你沒有提到語言

在Scala中,您可以通過控制器獲取路徑

val path= request.path

要么

val path=request.uri

我試過這個在游戲框架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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM