0

コントローラーで私はこれを持っています

public static Result index(String message, String alert) {
    return ok(index.render(message, alert));
}

ルートファイル

GET     /        controllers.Application.index(msg: String, alert: String)

次に、他の方法でこれらを返します:

return redirect(routes.Application.index("String message 1", "String message 2"));

return ok(index.render("String message 1", "String message 2"));

私がやりたいことは、 index.scala.html に表示する 2 つの文字列を渡してインデックス ページにリダイレクトすることです。

@(message: String, alert: String)

@main("Ready") {
    @if(message) { 
        <div class="alert">
          @Html(message)
          @Html(alert)
        </div>
    }
}

どちらのリターンも機能しません。Eclipse から次のエラーが表示されます。

The method index() in the type ReverseApplication is not applicable for the arguments (String, String)

そして、これはプレイのコンパイルから:

render(java.lang.String,java.lang.String) in views.html.index cannot be applied to (java.lang.String)

編集

render大丈夫ですが、インデックスページをレンダリングしますが、URLは古いままです。それが正しいか?

with redirect: ページをリダイレクトしますが、渡された文字列を URL に追加します

http://localhost/?message=Stringmessage1&alert=Stringmessage2

私が欲しいのは、文字列を渡すページへのリダイレクトですが、リダイレクトの URL があります。出来ますか?

4

2 に答える 2

1

あなたは物事を少し台​​無しにしました:

// This is a redirect to an action (public static Result index()) which in your case hasn't these 2 String args declared in route/method definition
return redirect(routes.Application.index("String message 1", "String message 2"));

// This one renders the view `index.scala.html`
return ok(index.render("String message 1", "String message 2"));

ヒント: インデックス ビュー ファイルの名前を ie に変更するだけです。indexView.scala.htmlそして次のように使用します:

return ok(indexView.render("String message 1", "String message 2"));

間違いを避けるために。

確認してください:リダイレクトで引数を使用できますが、ルートファイルで宣言する必要があり、Javaアクションではオプションではないことに注意してください。

于 2013-11-06T10:26:53.483 に答える
0

これは私が必要なことをしようとした最良の方法です:

コントローラ

public static Result save() {
  flash("success", "The item has been created");
  return redirect(routes.Application.index());
}

index.scala.html

  @if(flash.contains("success")) {
    <div class="alert">
      @flash().get("success")
    </div>
  }

を使用するとflash、URL を変更せずに、リダイレクトされたページに文字列を「渡す」ことができます。

于 2013-11-06T13:10:13.373 に答える