2016-05-13 90 views
6

私のアプリケーションのstruts.xmlには、Struts 2.3.28.1でうまく動作していました。 x.ApplicationHandler.editメソッドで処理されている/editApplicationアクションへの呼び出し。Struts 2.5へのアップデート後にワイルドカードアクションマッピングが機能しなくなった

<action name="*Application" class="x.ApplicationHandler" method="{1}"> 
    <result name="input">/WEB-INF/application.jsp</result> 
    <result name="success" type="redirectAction"> 
     <param name="actionName">browseApps</param> 
    </result> 
</action> 

Struts 2.5にアップグレードした後、これは機能しなくなりました。 /editApplicationアクションが404エラーを示して呼び出そう:

HTTP Status 404 - There is no Action mapped for namespace [/] and action name [editApplication]

私は、Struts 2.5リリースノートを確認しました、そしてワイルドカードベースのアクションマッピングの動作方法への更新の一切の言及が表示されません。この設定がもはや機能しない理由はありますか?

+2

これは既にAleksandrによって説明されているSMIのためです。メソッドが許可されていないと、メソッドが見つからない例外がスローされます。 "このメソッドは許可されていません"という例外をスローする方が良いかどうか、私は思っています。 –

+0

はい、より意味のある例外がここで非常に役立つかもしれません。 – john

+1

私はこのhttps://issues.apache.org/jira/browse/WW-4640をカバーする問題を登録しました –

答えて

14

Strict Method Invocationであり、Struts 2.5以降ではデフォルトで有効になっています。 SMIとワイルドカードマッピングに関するドキュメントから

:あなたは<package>ごとにそれを

When using wildcard mapping in actions' definitions SMI works in two ways:

  • SMI is disabled - any wildcard will be substituted with the default RegEx, ie.: <action name="Person*" method="perform*"> will be translated into allowedMethod = "regex:perform([A-Za-z0-9_$]*)" .
  • SMI is enabled - no wildcard substitution will happen, you must strictly define which methods can be accessed by annotations or <allowed-method/> tag.

無効にすることができます。

<package strict-method-invocation="false"> 

か、<allowed-methods>タグを使用して、アクションごとに許可されているメソッド名を追加することができます。

<action name="*Application" class="x.ApplicationHandler" method="{1}"> 
    <result name="input">/WEB-INF/application.jsp</result> 
    <result name="success" type="redirectAction"> 
     <param name="actionName">browseApps</param> 
    </result> 

    <allowed-methods>firstMethod, secondMethod, thirdMethod</allowed-methods> 
</action> 

または、<global-allowed-methods>タグを使用してパッケージごとに許可されるメソッド名を追加します。あなたは2.5にDTDの定義を更新する必要がありstruts.xmlに上記のタグを使用するためには

<package extends="struts-default"> 

    <global-allowed-methods>firstMethod, secondMethod, thirdMethod</global-allowed-methods> 

</package> 

NOTE

<?xml version="1.0" encoding="UTF-8" ?> 
<!DOCTYPE struts PUBLIC 
     "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN" 
     "http://struts.apache.org/dtds/struts-2.5.dtd"> 
<struts> 
... 
</struts> 

アクションが許可されたアクションメソッドを指定することができますstruts2-convention-plugin@AllowedMethods注釈もあります。

This annotation can be used directly on Action classes or in the package-info.java class in order to specify global allowed methods for all sub-packages.

関連する問題