S-JIS[2009-10-16/2009-12-05] 変更履歴

struts-config.xmlファイル

struts-config.xmlは、Strutsの設定を記述するファイル。
ファイルを分割して記述することも出来る。
Struts1.1以降では、モジュール分割で複数のコンフィグファイルに分けることが出来る。


バージョン

Struts1系は1.3までバージョンがあり、struts-config.xmlに書ける内容も異なっている。

Struts1.1

<!DOCTYPE struts-config PUBLIC
	"-//Apache Software Foundation//DTD Struts Configuration 1.1//EN"
	"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">

Struts1.2

<!DOCTYPE struts-config PUBLIC
	"-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
	"http://struts.apache.org/dtds/struts-config_1_2.dtd">

Struts1.3

<!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.xmlは単なるXMLファイルなので、ファイル内のDOCTYPE(DTD)を変えればそのバージョンのタグが記述できるようにはなる。
しかし、実行時に使用するStrutsライブラリーのバージョンがそれと一致していないと、実際の動作は当然行われない。

例えばStruts1.1と1.2にはforward要素にcontextRelativeという属性があるが、Struts1.3では廃止されている。
Struts1.3のDTDを指定している場合、contextRelativeを記述するとXMLファイルとしては不正になる。
Struts1.2のDTDを指定すればcontextRelativeをstruts-config.xml上に書くことが出来るが、ライブラリーが1.3だとcontextRelativeの処理は削除されているので、何も行われない。
また、Struts1.2で追加されたmodule属性も、DTDを1.2以降にすればstruts-config.xml上に記述できるが、ライブラリーが1.1のままなら当然使えない。


struts-config.xmlの要素

struts-config.xml内に書ける要素や順序は決まっている。[2009-12-05]

要素(Struts1.3) 概要 定義クラス 定義取得方法
struts-config     ModuleConfig moduleUtils.getModuleConfig(接頭辞,コンテキスト)
   display-name ?      
description ?      
form-beans ? フォーム定義    
   form-bean * FormBeanConfig moduleConfig.findFormBeanConfigs()
moduleConfig.findFormBeanConfig(フォーム名)
global-exceptions ? 共通例外処理    
  exception * ExceptionConfig moduleConfig.findExceptionConfigs()
moduleConfig.findExceptionConfig(クラス)
global-forwards ? 共通遷移先設定    
  forward * ForwardConfig moduleConfig.findForwardConfigs()
moduleConfig.findForwardConfig(フォワード名)
action-mappings ? リクエスト処理設定    
  action * ActionConfig
(ActionMapping)
moduleConfig.findActionConfigs()
moduleConfig.findActionConfig(パス)
   set-property *   値の取得方法
exception * ExceptionConfig actionConfig.findExceptionConfigs()
actionConfig.findExceptionConfig(クラス)
forward * ForwardConfig
(ActionForward)
actionConfig.findForwardConfigs()
actionConfig.findForwardConfig(フォワード名)
mapping.findForward(フォワード名)
controller ?   ControllerConfig moduleConfig.getControllerConfig()
message-resources * メッセージリソースファイルの指定 MessageResourcesConfig moduleConfig.findMessageResourcesConfigs()
moduleConfig.findMessageResourcesConfig(キー)
plug-in * プラグイン(初期処理・終了処理)定義 PlugInConfig moduleConfig.findPlugInConfigs()
  set-property *    

Struts目次へ戻る
メールの送信先:ひしだま