简体   繁体   English

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

[英]Play! framework form redirect not working

I´m having a problem redirecting from a play! 我有一个问题从播放重定向! form. 形成。 I think the problem lies in how I´m handling the routes. 我认为问题在于我如何处理路线。 The idea is that a user should be able to go to dashboard.html either by going first through index.hmtl using login from with a secruity key, or by typing directly in a valid path containing an access_token (using a qr-code redirection) 想法是用户应该能够通过使用登录来使用secruity密钥首先通过index.hmtl,或者直接在包含access_token的有效路径中输入(使用qr-code重定向)来访问dashboard.html

What I´m trying to do is as follows: 我想做的是如下:

1) login using a form on index.html (route: Application.index) 1)使用index.html上的表单登录(路由:Application.index)

Here is my form (located in index.html): 这是我的表单(位于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) authenticate and redirect to dashboard.html (route: Dashboard.dashboard) 2)验证并重定向到dashboard.html(路由:Dashboard.dashboard)

public static void dashboard(String access_token) {
   /*
      ...some code
   */

    render(username);
}


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

Here is my route file: 这是我的路线文件:

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

The dashboard route works fine if I call directly upon dashboard(String access_token) through an URL like: http://localhost:9000/dashboard?access_token=0000 But if i try to login using the login form that calls upon authenticate(String key) I get this URL http://localhost:9000/dashboard?access_token&key=1234 where key is the var being sent to the auth()function. 如果我通过以下URL直接调用仪表板(String access_token),仪表板路由工作正常: http:// localhost:9000 / dashboard?access_token = 0000但是如果我尝试使用调用authenticate的登录表单进行登录(String key) )我得到这个URL http:// localhost:9000 / dashboard?access_token&key = 1234其中key是发送到auth()函数的var。 Clearly my fault lies with the routes, but I have tried and tested the logic and I am 100% certain it is sound. 显然我的错是路线,但我已经尝试并测试了逻辑,我100%肯定它是合理的。 I´m using Play 1.2.4 I have spent two days on this problem and would be most grateful for any suggestions. 我正在使用Play 1.2.4我已经花了两天时间解决这个问题,并且非常感谢任何建议。

That actually seems like a bug. 这实际上似乎是一个错误。 Maybe try 也许试试吧

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

instead of 代替

dashboard(access_token);

The Java code seems fine. Java代码似乎很好。 Just in case, have you tried to change the routes file to: 为了以防万一,您是否尝试将路径文件更改为:

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

moving the GET before the POST (order matters, this should fix it if there is a Play bug on that section). 在POST之前移动GET(顺序很重要,如果该部分存在Play bug,则应该修复它)。

Another option is to simply rename the POST route, to fix the issue if it's caused by both routes having the same 'path'. 另一种选择是简单地重命名POST路由,以解决问题,如果它是由具有相同“路径”的两条路由引起的。

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

Problem Solved! 问题解决了!

What I forgot to mention...oops was that I am also using jQuery Mobile and the problem had to do with Play! 我忘了提到... oops是我也在使用jQuery Mobile,问题与Play有关! routing being overriden my jQuery Mobile page routing. 路由被覆盖我的jQuery Mobile页面路由。

I disabled the routing by adding the following script: 我通过添加以下脚本禁用了路由:

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

})

Using instructions on the jQuery website: http://jquerymobile.com/test/docs/api/globalconfig.html I implemented the above but the script needs to referenced in the .hmtml header in the following order: 使用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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM