玩!框架表单重定向不起作用



我从播放重定向时遇到问题!我认为问题在于我如何处理路线。这个想法是用户应该能够转到仪表板.html要么首先使用 index.hmtl 使用安全密钥登录,要么直接在包含access_token的有效路径中键入(使用 QR 码重定向)

我正在尝试做的是:

1) 使用索引上的表单登录.html(路由:Application.index)

这是我的表格(位于索引.html):

<form action="@{Dashboard.authenticate()}" method="POST" name="login">
    <input name="key" type="password" maxlength="128" value="${flash.key}">
    <input class="button" id="btnLogin" type="submit" value="Login">
</form>

2) 进行身份验证并重定向到仪表板.html(路由:仪表板.仪表板)

public static void dashboard(String access_token) {
   /*
      ...some code
   */
    render(username);
}

public static void authenticate(String key) {
   /*
      ...some code
   */
     dashboard(access_token);
}

这是我的路由文件:

# Home page 
GET     /                   Application.index
POST    /dashboard      Dashboard.authenticate
GET     /dashboard      Dashboard.dashboard

如果我通过以下 URL 直接调用仪表板(字符串 access_token),仪表板路由工作正常:http://localhost:9000/dashboard?access_token=0000但是,如果我尝试使用调用身份验证(字符串密钥)的登录表单登录,我会得到这个 URL http://localhost:9000/dashboard?access_token&key=1234 其中密钥是发送到 auth() 函数的变量。显然,我的错在于路线,但我已经尝试并测试了逻辑,我 100% 确定它是合理的。我正在使用播放 1.2.4我花了两天时间解决这个问题,如有任何建议,我将不胜感激。

这实际上似乎是一个错误。也许尝试

redirect("/dashboard?access_token="+access_token);

而不是

dashboard(access_token);

Java 代码似乎很好。以防万一,您是否尝试将路由文件更改为:

# Home page 
GET     /                   Application.index
GET     /dashboard      Dashboard.dashboard
POST    /dashboard      Dashboard.authenticate

在开机自检之前移动 GET(顺序很重要,如果该部分存在播放错误,这应该可以修复它)。

另一种选择是简单地重命名 POST 路由,以修复由两个路由具有相同"路径"引起的问题。

# Home page 
GET     /                    Application.index
GET     /dashboard           Dashboard.dashboard
POST    /dashboard/auth      Dashboard.authenticate

问题解决了!

我忘了提的...哎呀,我也在使用jQuery Mobile,问题与Play有关!路由被覆盖我的jQuery Mobile页面路由。

我通过添加以下脚本禁用了路由:

$(document).bind("mobileinit", function(){
    $.mobile.ajaxEnabled = false;
    $.mobile.linkBindingEnabled = false;
    $.mobile.hashListeningEnabled = false;
    $.mobile.pushStateEnabled = false;
    $.mobile.changePage.defaults.changeHash = false;
})

使用 jQuery 网站上的说明:http://jquerymobile.com/test/docs/api/globalconfig.html 我实现了上述内容,但脚本需要按以下顺序在 .hmtml 标头中引用:

<script src="jquery.js"></script>
<script src="custom-scripting.js"></script>
<script src="jquery-mobile.js"></script>

最新更新