この内容は古いバージョンです。最新バージョンを表示するには、戻るボタンを押してください。
バージョン:2
更新日時:2026-05-16 17:19:31
タイトル: ActionMapping
ActionMappingとは
ActionMappingは、Apache Struts (Struts 1) のクラスで、struts-config.xml に書いた「URL ↔ Action クラス ↔ 遷移先 (forward) 」のマッピング情報を保持するオブジェクトです。Action の execute() 内で mapping.findForward("success") のように、次の画面を取り出すために使われます。
ActionMappingの役割
| 項目 | 内容 |
| パッケージ | org.apache.struts.action.ActionMapping |
| 役割 | Action と遷移先 (forward) のマッピング情報を保持 |
| 設定元 | struts-config.xml の <action> 要素 |
| 主な使用箇所 | Action#execute(ActionMapping, ActionForm, HttpServletRequest, HttpServletResponse) の第1引数 |
struts-config.xmlの例
|
<action-mappings>
<action path="/login"
type="com.example.LoginAction"
name="loginForm"
scope="request"
input="/login.jsp">
<forward name="success" path="/menu.jsp" />
<forward name="failure" path="/login.jsp" />
</action>
</action-mappings>
|
ActionMappingの主なメソッド
| メソッド | 役割 |
findForward(String name) | 指定 forward 名の ActionForward を取得 |
getInputForward() | バリデーションエラー時の戻り先 |
getPath() | このマッピングの URL パス (/login 等) |
getName() | 関連付けられた ActionForm 名 |
getScope() | ActionForm のスコープ (request / session) |
getParameter() | parameter 属性の値 (DispatchActionで利用) |
Actionでの典型的な使い方
|
public class LoginAction extends Action {
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest req,
HttpServletResponse res) throws Exception {
LoginForm f = (LoginForm) form;
if (auth(f.getId(), f.getPw())) {
return mapping.findForward("success");
}
return mapping.findForward("failure");
}
}
|
関連オブジェクト
- ActionForm — リクエストパラメータを受け取る Bean
- ActionForward — 遷移先 JSP のパス情報
- ActionServlet — リクエストを受けて Action を呼び出すコントローラ
- RequestProcessor — リクエスト処理の中核ロジック
注意点
- Struts 1 は 2013年に EOL。新規開発では Spring MVC / Spring Boot を選択する
- Struts 2 では設計が大きく変わり、ActionMapping という名前のクラスは存在しない (XML or Annotation で
<action> 要素を記述)
- Struts 1 の脆弱性 (S2-045 等は Struts 2) や ClassLoader 関連の問題から、可能なら早期に移行する
関連