ユーザーは定義ファイル(Struts設定ファイル)で動作内容を指示します。
このStruts設定ファイルの定義内容に従い、ControllerはリクエストURLごとに処理の振り分け、Actionクラスの処理結果に応じた遷移先の呼び出し、例外発生時の対応などを実行します。
例
(struts-config.xml)
<!-- (1) -->
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
"http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-config>
<form-beans>
<!-- (2) -->
<form-bean name="formbean" type="sample.ExtActionForm" />
</form-beans>
<action-mappings>
<!-- (3) -->
<action path="/sample" type="sample.ExtAction" name="formbean" input="/input.jsp" >
<!-- (4) -->
<forward name="result" path="/result.jsp" />
</action>
</action-mappings>
</struts-config> |
(1) DOCTYPE指定
Struts設定ファイルの構文を定めたdtdファイルを指定します。
(2) form-beans
リクエストパラメーターなどを格納するJavaBeanクラスを定義します。
(3) action-mapping
リクエストパスごとに呼び出されるActionクラスを定義します。
(4) forward
処理結果を表示するページのパスを定義します。