web.xmlについて

広告

ここではweb.xmlの記述方法の詳細について見ていきます。デフォルトで使われるweb.xmlは下記の場所に置いてあります。

<Tomcatをインストールしたディレクトリ>\conf\web.xml

基本的な構成は下記のようになっています。

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
  version="2.4">

  ....

</web-app>

以前はDTD(Document Type Definition)で書式が定義されていましたが、今回のバージョンからはXML Schemaに変更となっています。実際どのように定義されているかは下記を参照して下さい。

XML Schemas for J2EE Deployment Descriptors

上記ページの下の方に色々なXML Schemaが定義されていますが、今回関係しているものは"web-app_2_4.xsd"です。また"web-app_2_4.xsd"の中で"j2ee_1_4.xsd"と"jsp_2_0.xsd"がインクルードされていますので、この3つのファイルに定義がされていることになります。

web-app_2_4.xsd

web-app_2_4.xsd

j2ee_1_4.xsd

j2ee_1_4.xsd

jsp_2_0.xsd

jsp_2_0.xsd

細かく見ていくと非常に長くなるのですが、まとめると下記のような構造となります。

<web-app>
 |
 +- <description>
 |
 +- <display-name>
 |
 +- <icon>
 |   |
 |   +- <small-icon>
 |   |
 |   +- <large-icon>
 |
 +- <distributable>
 |
 +- <context-param>
 |
 +- <filter>
 |
 +- <filter-mapping>
 |
 +- <listener>
 |
 +- <servlet>
 |
 +- <servlet-mapping>
 |
 +- <session-config>
 |
 +- <mime-mapping>
 |
 +- <welcome-file-list>
 |
 +- <error-page>
 |
 +- <jsp-config>
 |
 +- <security-constraint>
 |
 +- <login-config>
 |
 +- <security-role>
 |
 +- <env-entry>
 |
 +- <ejb-ref>
 |
 +- <ejb-local-ref>
 |
 +- <service-ref>
 |   |
 |   +- <description>
 |   |
 |   +- <display-name>
 |   |
 |   +- <icon>
 |   |   |
 |   |   +- <small-icon>
 |   |   |
 |   |   +- <large-icon>
 |   |
 |   +- <service-ref-name>
 |   |
 |   +- <service-interface>
 |   |
 |   +- <wsdl-file>
 |   |
 |   +- <jaxrpc-mapping-file>
 |   |
 |   +- <service-qname>
 |   |
 |   +- <port-component-ref>
 |   |
 |   +- <handler>
 |
 +- <resource-ref>
 |
 +- <resource-env-ref>
 |
 +- <message-destination-ref>
 |
 +- <message-destination>
 |
 +- <locale-encoding-mapping-list>
 |
</web-app>

( Written by Tatsuo Ikura )

Profile
profile_img

著者 / TATSUO IKURA

プログラミングや開発環境構築の解説サイトを運営しています。