3

私はStruts 2が初めてで、この構文に出くわしました(チュートリアルで推奨されています)。

<action name="Register_*" method="{1}" class="Register">
    <result name="input">/member/Register.jsp</result>
    <result type="redirectAction">Menu</result>
</action>

Register.{1} メソッドを呼び出すことは理解しています。問題は、ユーザーが別の (ランダムな) 値を入力して 500 エラーを引き起こす可能性があることです (エラーとして正しくログに記録されます)。

どうすればこれを防ぐことができますか?

4

2 に答える 2

8

私のアプリケーションでは、次のように使用します。

  <action name="*/*" class="{1}Action" method="{2}">
       <interceptor-ref name="CustomAuthStack" />       
            <result>/pages/{1}/{2}.jsp</result>
            <result name="input">/pages/error/denied.jsp</result>
            <result name="logout">/pages/error/denied.jsp</result>

            <!-- methods that come back to listing after processing -->
            <result name="remove" type="redirectAction">{1}/list</result>
            <result name="save"   type="redirectAction">{1}/list</result>
            <result name="enable"   type="redirectAction">{1}/list</result>

   ....

   </action>

myapp/users/list のような動作中のスラッシュについては、

<constant name="struts.enable.SlashesInActionNames" value="true" />

strus.xml で。

これで標準ができました:

アクション --> UserAction jsp --> users/list.jsp

于 2009-04-24T21:07:02.340 に答える
1

まず、Register.{1} メソッドを呼び出しません。Register_{1} を呼び出します。ここで、{1} はアクション タイプ (通常は編集、表示など) です。

URLが実際に

Register_View
Register_Edit
e.t.c.

そのため、ユーザーが手動で URL を次のような存在しないものに変更した場合

Register_methodThatDoesNotExist

その場合、struts 2 はエラーを返します。

しかし、なぜこれが問題なのですか?ユーザーが URL を手動で改ざんした場合、任意のテクノロジを使用する Web アプリケーションでは、エラーが返されます (404 も)。

あなたは正確に何を防ごうとしていますか?

アップデート:

500 エラーを防ぐには、すべてのアクション (ルールに一致しないもの) をキャッチし、エラー ページにリダイレクトします。Struts 2 wiki の「Wildcard Default」のデフォルト パラグラフを参照してください。

http://cwiki.apache.org/WW/action-configuration.html

これは、struts 構成の最後にある必要があります

于 2009-04-08T19:46:48.153 に答える