Playframework “提交”按钮中的查询字符串丢失

Playframework “提交”按钮中的查询字符串丢失,playframework,playframework-2.1,Playframework,Playframework 2.1,我对web应用程序和play框架都是新手,我问的问题可能很幼稚。然而,我在谷歌上搜索了一会儿,并没有找到一个好的答案,所以请容忍我 首先,我的平台是play-2.1.1+Java1.6+OSX10.8.3 这个问题的一个简短版本是:我有一个提交按钮的表单,带有action=“hello?id=100”。但是,当我单击按钮时,发送的请求似乎是hello?,而不是hello?id=100。此请求的操作需要参数id,因此我得到了hello?的一个错误 这是完整的设置 形态/路线: GET /

我对web应用程序和play框架都是新手,我问的问题可能很幼稚。然而,我在谷歌上搜索了一会儿,并没有找到一个好的答案,所以请容忍我

首先,我的平台是play-2.1.1+Java1.6+OSX10.8.3

这个问题的一个简短版本是:我有一个提交按钮的表单,带有action=“hello?id=100”。但是,当我单击按钮时,发送的请求似乎是
hello?
,而不是
hello?id=100
。此请求的操作需要参数
id
,因此我得到了
hello?
的一个错误

这是完整的设置

形态/路线:

GET     /                           controllers.Application.index()
GET     /hello                      controllers.Application.hello(id: Long)
app/controllers/Application.java:

package controllers;

import play.*;
import play.mvc.*;

import views.html.*;

public class Application extends Controller {

    public static Result index() {
        return ok(index.render());
    }

    public static Result hello(Long id) {
        return ok("Hello, No. " + id);
    }

}
app/views/index.scala.html

This is an index page.

<form name="helloButton" action="hello?id=100" method="get">
    <input type="submit" value="Hello">
</form>
这是一个索引页。
根据播放文档,应该从查询字符串
?id=100
中提取
id
。但是,当我单击提交按钮时,请求变成
hello?
,而不是
hello?id=100
,因此我得到如下错误:

<form name="helloButton" action="hello" method="get">
    <input type="hidden" name="id" value="100">
    <input type="submit" value="Hello">
</form>
请求“GET/hello?”[缺少参数:id]


有人能告诉我为什么会这样吗?提前感谢。

问题在于表单:

<form name="helloButton" action="hello?id=100" method="get">
    <input type="submit" value="Hello">
</form>

这将告诉浏览器将隐藏字段添加到查询字符串中,结果是
hello?id=100
。或者,您可以将表单方法更改为POST。

问题在于表单:

<form name="helloButton" action="hello?id=100" method="get">
    <input type="submit" value="Hello">
</form>

这将告诉浏览器将隐藏字段添加到查询字符串中,结果是
hello?id=100
。或者,您可以将表单方法更改为POST。

谢谢您,Sam。问题已解决。我选择了post解决方案。谢谢你,山姆。问题解决了。我选择了post解决方案。这能回答你的问题吗?这回答了你的问题吗?