2012-08-11 20 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显示错误与正则表达式适用于每个路线。