【问题标题】:How to redirect to another page using Scala Template如何使用 Scala 模板重定向到另一个页面
【发布时间】:2013-03-18 04:07:33
【问题描述】:

我有两个 html 页面:/algorithrms/algorithms/add 用 scala 模板编写。路由文件包含以下几行:

GET     /algorithms                 controllers.Application.algorithms()
GET     /algorithms/add             controllers.Application.newAlgorithmForm()

我想在页面/algorithms 中添加一个按钮,当我单击该按钮时,它只是重定向到第二个页面/algorithms/add。我知道如何在 JavaScript 中做到这一点。我只想通过单击按钮调用一个动作,然后让该动作将我重定向到登录页面。

所以我在第一页的html模板中添加了如下代码:

    @form(action=routes.Application.newAlgorithmForm()){
        <input type="submit" value="Add">
    }

成功了,但是登陆网址是:http://localhost:9000/algorithms/add?

我不想要那个问号。我想知道 1)我做错了什么导致问号生成以及 2)如何删除它?

【问题讨论】:

  • 如果您最终将使用表单发送信息(有一些其他表单字段),您可以将add 方法定义为POST 而不是GET。否则你可以听从 adis 的建议。
  • @EECOLOR 不,我不会随表格发送信息。所以你是对的,我想要的是 adis 的解决方案。

标签: html scala playframework-2.0


【解决方案1】:

我不知道你是否使用 Twitter 引导程序,但超链接也可以看起来像按钮,而 redirect to another page 在我看来就像一个普通的超链接:

<a class="btn" href="@controllers.routes.Application.newAlgorithmForm()" >
  @Messages("add.newAlgorithmForm")
</a>

【讨论】:

  • 我没有使用过引导程序,但我只是用我的代码试了一下。它工作得很好。谢谢!
猜你喜欢
  • 2015-03-12
  • 2011-02-22
  • 2011-06-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-22
  • 1970-01-01
相关资源
最近更新 更多