アクション・クラス:ForwardAction
ここでは、Strutsのアクション・クラスの内、ForwardActionクラスについて解説します。
- 実行環境
-
- ・WindowsXP Home Edition
- ・J2SDK 1.4.2_04
- ・Tomcat 5.0.18
- ・Struts 1.2.4
使用例
ForwardActionクラスはビジネスロジックの処理を行わず、単にリクエストの転送のみを行うアクション・クラスです。前ページ(exForAction.jsp)で入力された値を次ページ(exForAction2.jsp)で表示するプログラムを例に、ForwardActionクラスの使用方法について解説します。
ForwardActionクラスはstruts-config.xmlに指定するだけで使用できます。
【struts-config.xml】
<?xml version="1.0" encoding="Shift_JIS"?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
"http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<!-- (1)アクション・フォームBean
ExForActionFormクラスを指定します。 -->
<form-beans>
<form-bean
name="ExForAction"
type="struts.ExForActionForm" />
</form-beans>
<action-mappings>
<!-- (2)アクション・クラス ForwardActionクラスを指定します。 -->
<action path="/ExForAction"
type="org.apache.struts.actions.ForwardAction"
name="ExForAction"
scope="request"
parameter="/exForAction2.jsp" />
</action-mappings>
</struts-config>
- (1)<form-beans>タグで、アクション・フォームBeanの論理名とクラス名を指定します。
- (2)<action>タグのpath属性に、JSPのフォーム画面から指定される値を指定します。type属性にForwardActionクラスを指定します。ここでは、必ずorg.apache.struts.actions.ForwardActionと指定します。name属性にアクション・クラスが実行されたときに実行されるアクション・フォームBeanの論理名を指定します。scope属性にアクション・フォームBeanに保持されるプロパティのスコープを指定します。parameter属性にForwardActionクラスが実行されたときに遷移する遷移先を指定します。遷移先の指定は/ではじめる必要があります。
【exForAction.jsp】

【exForAction2.jsp】

11アクション・クラス:ForwardAction