Struts.xml

提供: Astarisk Works Wiki

struts2の設定ファイル、struts.xmlのメモ

Actionクラスのプロパティを設定する

次の様にするとWelcomeActionのmessageプロパティにHelloWorldという文字列を設定できる。

もちろん、WelcomeActionクラスに文字列を引数に取るmessageプロパティのゲッターが必要。設定によりアクションクラスの動作を変更したいときに便利。

<action name="index" class="WelcomeAction">
   <param name="message">HelloWorld</param>
   <result>/jsp/index.jsp</result>
</action>

また、ワイルドカードマッピングと組み合わせると動的に設定することも可能。

次の様に設定すると/ContextRoot/hogehoge-index とアクセスすればWelcomeActionのmessageプロパティには"hogehoge"という文字列が、/ContextRoot/wakuwaku-indexにアクセスすれば、"wakuwaku"が設定される。

<action name="*-index" class="WelcomeAction">
   <param name="message">{1}</param>
   <result>/jsp/index.jsp</result>
</action>
個人用ツール