2012-08-11 56 views
3

我不能似乎只要我添加第二個參數,得到多個參數,如果我加一個參數一切正常工作,我總是得到PlayFramework 2.0.2多個參數

No data received 
Unable to load the webpage because the server sent no data. 
Here are some suggestions: 
Reload this webpage later. 
Error 324 (net::ERR_EMPTY_RESPONSE): The server closed the connection without sending any data. 

能比誰確認您可以使用play 2.0.2爲請求添加第二個參數? (使用Java)

我的網址,因爲這

http://localhost:9000/account/foruser?username=somethig&create=0 

簡單和路線

GET  /account/foruser 
controllers.user.UserController.foruser(username:String, create:Boolean) 
+0

我也遇到了多個查詢字符串參數的問題。該文檔不排除這種情況,因此看起來像DynamicForm方法是一個解決方法。 – 2012-08-25 10:58:34

回答

13

你應該多放些注意力放在路線docs and samples

一般來說,如果您使用的命名參數爲&name=value,您無需在路徑文件中指定它們。而是使用Java中的DynamicForm來訪問它們。

路由文件用於將鏈接的unnamed部分與控制器的動作和參數進行匹配。所以,你的鏈接應該是這樣的:

http://localhost:9000/account/foruser/something/0 

和路由(當然這需要被放置在一個行路線文件:

GET  /account/foruser/:username/:create 
    controllers.user.UserController.foruser(username: String, create: Integer) 

請注意,是在使用布爾型的一些bug報告路線,所以它只是使用更安全一些數字類型,而不是

+0

我試圖使用表單提取網址中的數據,但我無法使其工作。我使用了常規的myform.get()方法來提取類的實例中的數據。你能給我們一個如何去做的例子嗎? – Moebius 2014-07-10 11:50:45

+0

@Moebius先給我URL的示例 – biesior 2014-07-10 15:00:13

0

@biesior我正在使用2.0.4有兩種類型的參數相同的問題

文件路徑:

GET /v2/object/all/data/:from/:until/:all   controllers.ObjectController.getAllData(from: String, until: String , all: Boolean, username: String ?= null, password: String ?=null) 

文件控制器:

public static Result getAllData(
      @PathParam("from") String from, 
      @PathParam("until") String until, 
      @PathParam("all") Boolean all, 
      @QueryParam("username") String username, @QueryParam("password") String password) 

做多次測試後,我終於解決了這個問題。您應該使用 「布爾」,而不是布爾,所以 「getAllData」 轉變爲:

public static Result getAllData(
      @PathParam("from") String from, 
      @PathParam("until") String until, 
      @PathParam("all") boolean all, 
      @QueryParam("username") String username, @QueryParam("password") String password) 
+0

我正在測試,看起來當我使用布爾類型時出現錯誤324 ... – gavioto 2013-02-01 21:54:17

+0

下面是更多的[布爾和2.0的問題](https://groups.google.com/d/topic/play-framework/5yCi6AvDnyo/discussion)(解決在2.1中),所以我推薦使用整數 – gavioto 2013-02-01 22:31:29

0

一個簡單的例子:

對應於這條路線正確的網址:

GET  /user/update:action/:id controllers.myFunction(action: String, id: String) 

是URL :

myWebsite.com/user/update$action=update/[email protected] 

需要注意的是:

  • 每一個url參數開始於$
  • 否&或?在網址中!
  • /between:id和:action必須在那裏。沒有它就會重定向到正確的網頁,但是如果你想擁有正確的值(即action =>'$ action = update'和id =>'$ id = a @ a'fr')傳輸到你的函數
  • 當你有一個錯誤,Java顯示錯誤與正則表達式適用於每個路線。