Struts 2 –複数のStruts構成ファイルを含める
Struts 2には、複数のStruts構成ファイルを1つのユニットに含めるための「include file」機能が付属しています。
シングルStruts構成ファイル
悪いStruts 2の構成例を見てみましょう。
struts.xml
pages/welcome_audit.jsp pages/welcome_user.jsp
上記のStruts構成ファイルでは、すべての「user」および「audit」設定が単一のファイルwhich is not recommend and MUST BE AVOIDにグループ化されています。 このstruts.xmlファイルをより小さなモジュール関連の部分に分割する必要があります。
これがケーススタディであるとは思わないでください。real lifeで発生しました。 多くのStruts 1または2の開発者が、すべてを単一のStruts構成ファイルにグループ化するのを見ました。 実際、多くの人はまだStrutsのインクルードファイル機能を認識していません。
複数のStruts構成ファイル
Struts 2では、各モジュールに常にStruts構成ファイルを割り当てる必要があります。 この場合、次の3つのファイルを作成できます。
-
struts-audit.xml – Put all audit module settings here.
-
struts-user.xml – Put all user modules settings here.
-
struts.xml – Put default settings and include the struts-audit.xml and struts-user.xml.
struts-audit.xml
pages/welcome_audit.jsp
struts-user.xml
pages/welcome_user.jsp
struts.xml
フォルダー構造がどのように見えるかを見る