24

ActionMessages表示されないアクションの実行中に create で問題が発生しましたが、問題はstruts redirect=true-config.xml にある forward が原因であることがわかりました。

デフォルトの動作はredirect=falseであるため、どのような利点があるかを考えていましたがredirect=true、答えが見つかりませんでした。アクションフォワードでいつ、なぜredirect=true使用する必要があるかを知っている人はいますか?

4

3 に答える 3

38

「二重送信の問題」を防ぎます

POST に応答してページを表示しない

常に GET を使用してページをロードする

REDIRECT を使用して POST から GET に移動する

詳細はこちらこちら

于 2009-03-05T12:20:35.707 に答える
28

Redirect は、ブラウザーに新しい要求を行うように強制する応答をブラウザーに送信します。サーバーの観点から見ると、ブラウザーは (自動的ではありますが) 新しい要求を行うだけです。リダイレクトの特徴:

  • 既存のパラメーターと属性が破棄され、URL で指定したパラメーターを使用して新しい要求が形成されます。
  • 新しい URL はブラウザーに表示され、ユーザーはそれをブックマークできます。
  • ブラウザーとの往復に時間がかかるため、速度が遅くなる可能性があります。

A forward happens on the server. The browser is not involved in this. Some characteristics of the forward:

  • New parameters are added or overwrite existing parameters. So the existing parameters cannot be removed from the request.
  • Stuff can be added in request context, it will remain available. You can pass information in this way.
  • The URL is not changed in the browser, for the browser the original address remains intact.
  • You can only forward to another URL in the same application.

So it depends on what you want to accomplish. A forward is generally spoken faster. But if the user should be able to bookmark the new location, it is not an option.

于 2009-03-11T20:45:14.070 に答える