web.xml深入了解——各种标签

项目实例web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" 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">

	<display-name>wm5920 Web</display-name>

<!--
	<context-param>
		<param-name>log4jConfigLocation</param-name>
		<param-value>/WEB-INF/classes/log4j.xml</param-value>
	</context-param>
 -->
	<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>/WEB-INF/applicationContext.xml</param-value>
	</context-param>

	<context-param>
		<param-name>webAppRootKey</param-name>
		<param-value>wm5920Web.root</param-value>
	</context-param>


<!--
<session-config>
		<session-timeout>10</session-timeout>
	</session-config>
 -->

	<error-page>
		<exception-type>java.lang.Exception</exception-type>
			<location>/pages/error.jsp</location>
	</error-page>


	<welcome-file-list>
		<welcome-file>/static/html/index.html</welcome-file>
	</welcome-file-list>

<!--
	<filter>
		<filter-name>httpMethodFilter</filter-name>
		<filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
	</filter>
 -->
    <filter>
        <filter-name>localizationFilter</filter-name>
        <filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
    </filter>

	<filter>
		<filter-name>CharacterEncodingFilter</filter-name>
		<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>
		<init-param>
			<param-name>forceEncoding</param-name>
			<param-value>true</param-value>
		</init-param>
	</filter>

	<filter>
  		<filter-name>springSecurityFilterChain</filter-name>
  		<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
	</filter>
	<filter-mapping>
    	<filter-name>CharacterEncodingFilter</filter-name>
    	<url-pattern>/*</url-pattern>
  	</filter-mapping>

  	<filter-mapping>
    	<filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
     	<dispatcher>FORWARD</dispatcher>
    	<dispatcher>REQUEST</dispatcher>
    </filter-mapping>


    <filter-mapping>
        <filter-name>localizationFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!--
    <filter-mapping>
		<filter-name>httpMethodFilter</filter-name>
		<servlet-name>wm5920Web</servlet-name>
	</filter-mapping>
	 -->

    <listener>
		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
	</listener>
    <listener>
		<listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
	</listener>
<!--
	<listener>
		<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
	</listener>
	 -->
	<servlet>
		<servlet-name>wm5920Web</servlet-name>
		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
		<load-on-startup>2</load-on-startup>
	</servlet>

	<!--
	<servlet-mapping>
		<servlet-name>default</servlet-name>
		<url-pattern>/static/*</url-pattern>
	</servlet-mapping>
	 -->
	<servlet-mapping>
		<servlet-name>wm5920Web</servlet-name>
		<url-pattern>*.do</url-pattern>
	</servlet-mapping>
	<servlet-mapping>
		<servlet-name>wm5920Web</servlet-name>
		<url-pattern>*.form</url-pattern>
	</servlet-mapping>
	<jsp-config>
		<taglib>
			<taglib-uri>http://www.webwm5920.com/tags/common</taglib-uri>
			<taglib-location>/WEB-INF/tld/wm5920.tld</taglib-location>
		</taglib>
	</jsp-config>
</web-app>

xmlns是xml namespace的缩写,即xml的命名空间

xsi是xml schema instance的缩写,即xml模式(架构)实例

xsi:schemaLocation 由多个url组成,空格间隔,一般第二个url即为模式存放的位置,本例中是web-app_2_4.xsd,我们看下

源码:

<?xml version="1.0" encoding="UTF-8"?>
<!--
 Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->
<xsd:schema xmlns="http://www.w3.org/2001/XMLSchema"
            targetNamespace="http://java.sun.com/xml/ns/j2ee"
            xmlns:j2ee="http://java.sun.com/xml/ns/j2ee"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            elementFormDefault="qualified"
            attributeFormDefault="unqualified"
            version="2.4">
  <xsd:annotation>
    <xsd:documentation>
      %W% %E%
    </xsd:documentation>
  </xsd:annotation>

  <xsd:annotation>
    <xsd:documentation>
      <![CDATA[

        This is the XML Schema for the Servlet 2.4 deployment descriptor.
        The deployment descriptor must be named "WEB-INF/web.xml" in the
        web application's war file.  All Servlet deployment descriptors
        must indicate the web application schema by using the J2EE
        namespace:

        http://java.sun.com/xml/ns/j2ee

        and by indicating the version of the schema by
        using the version element as shown below:

            <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="..."
              version="2.4">
              ...
            </web-app>

        The instance documents may indicate the published version of
        the schema using the xsi:schemaLocation attribute for J2EE
        namespace with the following location:

        http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd

        ]]>
    </xsd:documentation>
  </xsd:annotation>

  <xsd:annotation>
    <xsd:documentation>

      The following conventions apply to all J2EE
      deployment descriptor elements unless indicated otherwise.

      - In elements that specify a pathname to a file within the
        same JAR file, relative filenames (i.e., those not
        starting with "/") are considered relative to the root of
        the JAR file's namespace.  Absolute filenames (i.e., those
        starting with "/") also specify names in the root of the
        JAR file's namespace.  In general, relative names are
        preferred.  The exception is .war files where absolute
        names are preferred for consistency with the Servlet API.

    </xsd:documentation>
  </xsd:annotation>

  <xsd:include schemaLocation="j2ee_1_4.xsd"/>
  <xsd:include schemaLocation="jsp_2_0.xsd"/>


<!-- **************************************************** -->


  <xsd:element name="web-app" type="j2ee:web-appType">
    <xsd:annotation>
      <xsd:documentation>

        The web-app element is the root of the deployment
        descriptor for a web application.  Note that the sub-elements
        of this element can be in the arbitrary order. Because of
        that, the multiplicity of the elements of distributable,
        session-config, welcome-file-list, jsp-config, login-config,
        and locale-encoding-mapping-list was changed from "?" to "*"
        in this schema.  However, the deployment descriptor instance
        file must not contain multiple elements of session-config,
        jsp-config, and login-config. When there are multiple elements of
        welcome-file-list or locale-encoding-mapping-list, the container
        must concatenate the element contents.  The multiple occurrence
        of the element distributable is redundant and the container
        treats that case exactly in the same way when there is only
        one distributable.

      </xsd:documentation>
    </xsd:annotation>

    <xsd:unique name="web-app-servlet-name-uniqueness">
      <xsd:annotation>
        <xsd:documentation>

          The servlet element contains the name of a servlet.
          The name must be unique within the web application.

        </xsd:documentation>
      </xsd:annotation>
      <xsd:selector xpath="j2ee:servlet"/>
      <xsd:field    xpath="j2ee:servlet-name"/>
    </xsd:unique>

    <xsd:unique name="web-app-filter-name-uniqueness">
      <xsd:annotation>
        <xsd:documentation>

          The filter element contains the name of a filter.
          The name must be unique within the web application.

        </xsd:documentation>
      </xsd:annotation>
      <xsd:selector xpath="j2ee:filter"/>
      <xsd:field    xpath="j2ee:filter-name"/>
    </xsd:unique>

    <xsd:unique name="web-app-ejb-local-ref-name-uniqueness">
      <xsd:annotation>
        <xsd:documentation>

          The ejb-local-ref-name element contains the name of an EJB
          reference. The EJB reference is an entry in the web
          application's environment and is relative to the
          java:comp/env context.  The name must be unique within
          the web application.

          It is recommended that name is prefixed with "ejb/".

        </xsd:documentation>
      </xsd:annotation>
      <xsd:selector xpath="j2ee:ejb-local-ref"/>
      <xsd:field    xpath="j2ee:ejb-ref-name"/>
    </xsd:unique>

    <xsd:unique name="web-app-ejb-ref-name-uniqueness">
      <xsd:annotation>
        <xsd:documentation>

          The ejb-ref-name element contains the name of an EJB
          reference. The EJB reference is an entry in the web
          application's environment and is relative to the
          java:comp/env context.  The name must be unique within
          the web application.

          It is recommended that name is prefixed with "ejb/".

        </xsd:documentation>
      </xsd:annotation>
      <xsd:selector xpath="j2ee:ejb-ref"/>
      <xsd:field    xpath="j2ee:ejb-ref-name"/>
    </xsd:unique>

    <xsd:unique name="web-app-resource-env-ref-uniqueness">
      <xsd:annotation>
        <xsd:documentation>

          The resource-env-ref-name element specifies the name of
          a resource environment reference; its value is the
          environment entry name used in the web application code.
          The name is a JNDI name relative to the java:comp/env
          context and must be unique within a web application.

        </xsd:documentation>
      </xsd:annotation>
      <xsd:selector xpath="j2ee:resource-env-ref"/>
      <xsd:field    xpath="j2ee:resource-env-ref-name"/>
    </xsd:unique>

    <xsd:unique name="web-app-message-destination-ref-uniqueness">
      <xsd:annotation>
        <xsd:documentation>

          The message-destination-ref-name element specifies the name of
          a message destination reference; its value is the
          environment entry name used in the web application code.
          The name is a JNDI name relative to the java:comp/env
          context and must be unique within a web application.

        </xsd:documentation>
      </xsd:annotation>
      <xsd:selector xpath="j2ee:message-destination-ref"/>
      <xsd:field    xpath="j2ee:message-destination-ref-name"/>
    </xsd:unique>

    <xsd:unique name="web-app-res-ref-name-uniqueness">
      <xsd:annotation>
        <xsd:documentation>

          The res-ref-name element specifies the name of a
          resource manager connection factory reference.  The name
          is a JNDI name relative to the java:comp/env context.
          The name must be unique within a web application.

        </xsd:documentation>
      </xsd:annotation>
      <xsd:selector xpath="j2ee:resource-ref"/>
      <xsd:field    xpath="j2ee:res-ref-name"/>
    </xsd:unique>

    <xsd:unique name="web-app-env-entry-name-uniqueness">
      <xsd:annotation>
        <xsd:documentation>

          The env-entry-name element contains the name of a web
          application's environment entry.  The name is a JNDI
          name relative to the java:comp/env context.  The name
          must be unique within a web application.

        </xsd:documentation>
      </xsd:annotation>

      <xsd:selector xpath="j2ee:env-entry"/>
      <xsd:field    xpath="j2ee:env-entry-name"/>
    </xsd:unique>

    <xsd:key name="web-app-role-name-key">
      <xsd:annotation>
        <xsd:documentation>

          A role-name-key is specified to allow the references
          from the security-role-refs.

        </xsd:documentation>
      </xsd:annotation>
      <xsd:selector xpath="j2ee:security-role"/>
      <xsd:field    xpath="j2ee:role-name"/>
    </xsd:key>

    <xsd:keyref name="web-app-role-name-references"
                refer="j2ee:web-app-role-name-key">
      <xsd:annotation>
        <xsd:documentation>

          The keyref indicates the references from
          security-role-ref to a specified role-name.

        </xsd:documentation>
      </xsd:annotation>
      <xsd:selector xpath="j2ee:servlet/j2ee:security-role-ref"/>
      <xsd:field    xpath="j2ee:role-link"/>
    </xsd:keyref>
  </xsd:element>


<!-- **************************************************** -->

  <xsd:complexType name="auth-constraintType">
    <xsd:annotation>
      <xsd:documentation>

        The auth-constraintType indicates the user roles that
        should be permitted access to this resource
        collection. The role-name used here must either correspond
        to the role-name of one of the security-role elements
        defined for this web application, or be the specially
        reserved role-name "*" that is a compact syntax for
        indicating all roles in the web application. If both "*"
        and rolenames appear, the container interprets this as all
        roles.  If no roles are defined, no user is allowed access
        to the portion of the web application described by the
        containing security-constraint.  The container matches
        role names case sensitively when determining access.

      </xsd:documentation>
    </xsd:annotation>

    <xsd:sequence>
      <xsd:element name="description"
                   type="j2ee:descriptionType"
                   minOccurs="0" maxOccurs="unbounded"/>
      <xsd:element name="role-name"
                   type="j2ee:role-nameType"
                   minOccurs="0" maxOccurs="unbounded"/>
    </xsd:sequence>
    <xsd:attribute name="id" type="xsd:ID"/>
  </xsd:complexType>

<!-- **************************************************** -->

  <xsd:complexType name="auth-methodType">
    <xsd:annotation>
      <xsd:documentation>

        The auth-methodType is used to configure the authentication
        mechanism for the web application. As a prerequisite to
        gaining access to any web resources which are protected by
        an authorization constraint, a user must have authenticated
        using the configured mechanism. Legal values are "BASIC",
        "DIGEST", "FORM", "CLIENT-CERT", or a vendor-specific
        authentication scheme.

        Used in: login-config

      </xsd:documentation>
    </xsd:annotation>

    <xsd:simpleContent>
      <xsd:restriction base="j2ee:string"/>
    </xsd:simpleContent>
  </xsd:complexType>

<!-- **************************************************** -->

  <xsd:complexType name="dispatcherType">
    <xsd:annotation>
      <xsd:documentation>

        The dispatcher has four legal values: FORWARD, REQUEST, INCLUDE,
        and ERROR. A value of FORWARD means the Filter will be applied
        under RequestDispatcher.forward() calls.  A value of REQUEST
        means the Filter will be applied under ordinary client calls to
        the path or servlet. A value of INCLUDE means the Filter will be
        applied under RequestDispatcher.include() calls.  A value of
        ERROR means the Filter will be applied under the error page
        mechanism.  The absence of any dispatcher elements in a
        filter-mapping indicates a default of applying filters only under
        ordinary client calls to the path or servlet.

      </xsd:documentation>
    </xsd:annotation>

    <xsd:simpleContent>
      <xsd:restriction base="j2ee:string">
        <xsd:enumeration value="FORWARD"/>
        <xsd:enumeration value="INCLUDE"/>
        <xsd:enumeration value="REQUEST"/>
        <xsd:enumeration value="ERROR"/>
      </xsd:restriction>
    </xsd:simpleContent>
  </xsd:complexType>

<!-- **************************************************** -->

  <xsd:simpleType name="encodingType">
    <xsd:annotation>
      <xsd:documentation>

        The encodingType defines IANA character sets.

      </xsd:documentation>
    </xsd:annotation>

    <xsd:restriction base="xsd:string">
      <xsd:pattern value="[^\s]+"/>
    </xsd:restriction>
  </xsd:simpleType>

<!-- **************************************************** -->

  <xsd:complexType name="error-codeType">
    <xsd:annotation>
      <xsd:documentation>

        The error-code contains an HTTP error code, ex: 404

        Used in: error-page

      </xsd:documentation>
    </xsd:annotation>

    <xsd:simpleContent>
      <xsd:restriction base="j2ee:xsdPositiveIntegerType">
        <xsd:pattern value="\d{3}"/>
        <xsd:attribute name="id" type="xsd:ID"/>
      </xsd:restriction>
    </xsd:simpleContent>
  </xsd:complexType>

<!-- **************************************************** -->

  <xsd:complexType name="error-pageType">
    <xsd:annotation>
      <xsd:documentation>

        The error-pageType contains a mapping between an error code
        or exception type to the path of a resource in the web
        application.

        Used in: web-app

      </xsd:documentation>
    </xsd:annotation>

    <xsd:sequence>
      <xsd:choice>
        <xsd:element name="error-code"
                     type="j2ee:error-codeType"/>

        <xsd:element name="exception-type"
                     type="j2ee:fully-qualified-classType">
          <xsd:annotation>
            <xsd:documentation>

              The exception-type contains a fully qualified class
              name of a Java exception type.

            </xsd:documentation>
          </xsd:annotation>
        </xsd:element>
      </xsd:choice>

      <xsd:element name="location"
                   type="j2ee:war-pathType">
        <xsd:annotation>
          <xsd:documentation>

            The location element contains the location of the
            resource in the web application relative to the root of
            the web application. The value of the location must have
            a leading `/'.

          </xsd:documentation>
        </xsd:annotation>
      </xsd:element>
    </xsd:sequence>
    <xsd:attribute name="id" type="xsd:ID"/>
  </xsd:complexType>

<!-- **************************************************** -->

  <xsd:complexType name="filter-mappingType">
    <xsd:annotation>
      <xsd:documentation>

        Declaration of the filter mappings in this web
        application is done by using filter-mappingType.
        The container uses the filter-mapping
        declarations to decide which filters to apply to a request,
        and in what order. The container matches the request URI to
        a Servlet in the normal way. To determine which filters to
        apply it matches filter-mapping declarations either on
        servlet-name, or on url-pattern for each filter-mapping
        element, depending on which style is used. The order in
        which filters are invoked is the order in which
        filter-mapping declarations that match a request URI for a
        servlet appear in the list of filter-mapping elements. The
        filter-name value must be the value of the filter-name
        sub-elements of one of the filter declarations in the
        deployment descriptor.

      </xsd:documentation>
    </xsd:annotation>

    <xsd:sequence>
      <xsd:element name="filter-name"
                   type="j2ee:filter-nameType"/>
      <xsd:choice>
        <xsd:element name="url-pattern"
                     type="j2ee:url-patternType"/>
        <xsd:element name="servlet-name"
                     type="j2ee:servlet-nameType"/>
      </xsd:choice>
      <xsd:element name="dispatcher"
                   type="j2ee:dispatcherType"
                   minOccurs="0" maxOccurs="4"/>
    </xsd:sequence>
    <xsd:attribute name="id" type="xsd:ID"/>
  </xsd:complexType>

<!-- **************************************************** -->

  <xsd:complexType name="filter-nameType">
    <xsd:annotation>
      <xsd:documentation>

        The logical name of the filter is declare
        by using filter-nameType. This name is used to map the
        filter.  Each filter name is unique within the web
        application.

        Used in: filter, filter-mapping

      </xsd:documentation>
    </xsd:annotation>

    <xsd:simpleContent>
      <xsd:extension base="j2ee:nonEmptyStringType"/>
    </xsd:simpleContent>
  </xsd:complexType>

<!-- **************************************************** -->

  <xsd:complexType name="filterType">
    <xsd:annotation>
      <xsd:documentation>

        The filterType is used to declare a filter in the web
        application. The filter is mapped to either a servlet or a
        URL pattern in the filter-mapping element, using the
        filter-name value to reference. Filters can access the
        initialization parameters declared in the deployment
        descriptor at runtime via the FilterConfig interface.

        Used in: web-app

      </xsd:documentation>
    </xsd:annotation>

    <xsd:sequence>
      <xsd:group ref="j2ee:descriptionGroup"/>
      <xsd:element name="filter-name"
                   type="j2ee:filter-nameType"/>
      <xsd:element name="filter-class"
                   type="j2ee:fully-qualified-classType">
        <xsd:annotation>
          <xsd:documentation>

            The fully qualified classname of the filter.

          </xsd:documentation>
        </xsd:annotation>
      </xsd:element>

      <xsd:element name="init-param"
                   type="j2ee:param-valueType"
                   minOccurs="0" maxOccurs="unbounded">
        <xsd:annotation>
          <xsd:documentation>

            The init-param element contains a name/value pair as
            an initialization param of a servlet filter

          </xsd:documentation>
        </xsd:annotation>
      </xsd:element>
    </xsd:sequence>
    <xsd:attribute name="id" type="xsd:ID"/>
  </xsd:complexType>

<!-- **************************************************** -->

  <xsd:complexType name="form-login-configType">
    <xsd:annotation>
      <xsd:documentation>

        The form-login-configType specifies the login and error
        pages that should be used in form based login. If form based
        authentication is not used, these elements are ignored.

        Used in: login-config

      </xsd:documentation>
    </xsd:annotation>

    <xsd:sequence>

      <xsd:element name="form-login-page"
                   type="j2ee:war-pathType">
        <xsd:annotation>
          <xsd:documentation>

            The form-login-page element defines the location in the web
            app where the page that can be used for login can be
            found.  The path begins with a leading / and is interpreted
            relative to the root of the WAR.

          </xsd:documentation>
        </xsd:annotation>
      </xsd:element>

      <xsd:element name="form-error-page"
                   type="j2ee:war-pathType">
        <xsd:annotation>
          <xsd:documentation>

            The form-error-page element defines the location in
            the web app where the error page that is displayed
            when login is not successful can be found.
            The path begins with a leading / and is interpreted
            relative to the root of the WAR.

          </xsd:documentation>
        </xsd:annotation>
      </xsd:element>

    </xsd:sequence>
    <xsd:attribute name="id" type="xsd:ID"/>
  </xsd:complexType>

<!-- **************************************************** -->

  <xsd:complexType name="http-methodType">
    <xsd:annotation>

      <xsd:documentation>

        The http-method contains an HTTP method recognized by the
        web-app, for example GET, POST, ...

      </xsd:documentation>
    </xsd:annotation>

    <xsd:simpleContent>
      <xsd:restriction base="j2ee:string">
        <xsd:enumeration value="GET"/>
        <xsd:enumeration value="POST"/>
        <xsd:enumeration value="PUT"/>
        <xsd:enumeration value="DELETE"/>
        <xsd:enumeration value="HEAD"/>
        <xsd:enumeration value="OPTIONS"/>
        <xsd:enumeration value="TRACE"/>
      </xsd:restriction>
    </xsd:simpleContent>
  </xsd:complexType>

<!-- **************************************************** -->

  <xsd:complexType name="locale-encoding-mapping-listType">
    <xsd:annotation>
      <xsd:documentation>

        The locale-encoding-mapping-list contains one or more
        locale-encoding-mapping(s).

      </xsd:documentation>
    </xsd:annotation>

    <xsd:sequence>
      <xsd:element name="locale-encoding-mapping"
                   type="j2ee:locale-encoding-mappingType"
                   maxOccurs="unbounded"/>
    </xsd:sequence>
    <xsd:attribute name="id" type="xsd:ID"/>
  </xsd:complexType>

<!-- **************************************************** -->

  <xsd:complexType name="locale-encoding-mappingType">
    <xsd:annotation>
      <xsd:documentation>

        The locale-encoding-mapping contains locale name and
        encoding name. The locale name must be either "Language-code",
        such as "ja", defined by ISO-639 or "Language-code_Country-code",
        such as "ja_JP".  "Country code" is defined by ISO-3166.

      </xsd:documentation>
    </xsd:annotation>

    <xsd:sequence>
      <xsd:element name="locale"
                   type="j2ee:localeType"/>
      <xsd:element name="encoding"
                   type="j2ee:encodingType"/>
    </xsd:sequence>
    <xsd:attribute name="id" type="xsd:ID"/>
  </xsd:complexType>

<!-- **************************************************** -->

  <xsd:simpleType name="localeType">
    <xsd:annotation>
      <xsd:documentation>

        The localeType defines valid locale defined by ISO-639-1
        and ISO-3166.

      </xsd:documentation>
    </xsd:annotation>

    <xsd:restriction base="xsd:string">
      <xsd:pattern value="[a-z]{2}(_|-)?([\p{L}\-\p{Nd}]{2})?"/>
    </xsd:restriction>
  </xsd:simpleType>

<!-- **************************************************** -->

  <xsd:complexType name="login-configType">
    <xsd:annotation>
      <xsd:documentation>

        The login-configType is used to configure the authentication
        method that should be used, the realm name that should be
        used for this application, and the attributes that are
        needed by the form login mechanism.

        Used in: web-app

      </xsd:documentation>
    </xsd:annotation>

    <xsd:sequence>
      <xsd:element name="auth-method"
                   type="j2ee:auth-methodType"
                   minOccurs="0"/>
      <xsd:element name="realm-name"
                   type="j2ee:string" minOccurs="0">
        <xsd:annotation>
          <xsd:documentation>

            The realm name element specifies the realm name to
            use in HTTP Basic authorization.

          </xsd:documentation>
        </xsd:annotation>
      </xsd:element>
      <xsd:element name="form-login-config"
                   type="j2ee:form-login-configType"
                   minOccurs="0"/>
    </xsd:sequence>
    <xsd:attribute name="id" type="xsd:ID"/>
  </xsd:complexType>

<!-- **************************************************** -->

  <xsd:complexType name="mime-mappingType">
    <xsd:annotation>
      <xsd:documentation>

        The mime-mappingType defines a mapping between an extension
        and a mime type.

        Used in: web-app

      </xsd:documentation>
    </xsd:annotation>

    <xsd:sequence>
      <xsd:annotation>
        <xsd:documentation>

          The extension element contains a string describing an
          extension. example: "txt"

        </xsd:documentation>
      </xsd:annotation>

      <xsd:element name="extension"
                   type="j2ee:string"/>
      <xsd:element name="mime-type"
                   type="j2ee:mime-typeType"/>
    </xsd:sequence>
    <xsd:attribute name="id" type="xsd:ID"/>
  </xsd:complexType>

<!-- **************************************************** -->

  <xsd:complexType name="mime-typeType">
    <xsd:annotation>
      <xsd:documentation>

        The mime-typeType is used to indicate a defined mime type.

        Example:
        "text/plain"

        Used in: mime-mapping

      </xsd:documentation>
    </xsd:annotation>

    <xsd:simpleContent>
      <xsd:restriction base="j2ee:string">
          <xsd:pattern value="[^\p{Cc}^\s]+/[^\p{Cc}^\s]+"/>
      </xsd:restriction>
    </xsd:simpleContent>
  </xsd:complexType>

<!-- **************************************************** -->

  <xsd:complexType name="nonEmptyStringType">
    <xsd:annotation>
      <xsd:documentation>
        This type defines a string which contains at least one
        character.
      </xsd:documentation>
    </xsd:annotation>
    <xsd:simpleContent>
      <xsd:restriction base="j2ee:string">
        <xsd:minLength value="1"/>
      </xsd:restriction>
    </xsd:simpleContent>
  </xsd:complexType>

<!-- **************************************************** -->

  <xsd:complexType name="security-constraintType">
    <xsd:annotation>
      <xsd:documentation>

        The security-constraintType is used to associate
        security constraints with one or more web resource
        collections

        Used in: web-app

      </xsd:documentation>
    </xsd:annotation>

    <xsd:sequence>
      <xsd:element name="display-name"
                   type="j2ee:display-nameType"
                   minOccurs="0"
                   maxOccurs="unbounded"/>
      <xsd:element name="web-resource-collection"
                   type="j2ee:web-resource-collectionType"
                   maxOccurs="unbounded"/>
      <xsd:element name="auth-constraint"
                   type="j2ee:auth-constraintType"
                   minOccurs="0"/>
      <xsd:element name="user-data-constraint"
                   type="j2ee:user-data-constraintType"
                   minOccurs="0"/>
    </xsd:sequence>
    <xsd:attribute name="id" type="xsd:ID"/>
  </xsd:complexType>

<!-- **************************************************** -->

  <xsd:complexType name="servlet-mappingType">
    <xsd:annotation>
      <xsd:documentation>

        The servlet-mappingType defines a mapping between a
        servlet and a url pattern.

        Used in: web-app

      </xsd:documentation>
    </xsd:annotation>

    <xsd:sequence>
      <xsd:element name="servlet-name"
                   type="j2ee:servlet-nameType"/>
      <xsd:element name="url-pattern"
                   type="j2ee:url-patternType"/>
    </xsd:sequence>
    <xsd:attribute name="id" type="xsd:ID"/>
  </xsd:complexType>

<!-- **************************************************** -->

  <xsd:complexType name="servlet-nameType">
    <xsd:annotation>
      <xsd:documentation>

        The servlet-name element contains the canonical name of the
        servlet. Each servlet name is unique within the web
        application.

      </xsd:documentation>
    </xsd:annotation>

    <xsd:simpleContent>
      <xsd:extension base="j2ee:nonEmptyStringType"/>
    </xsd:simpleContent>
  </xsd:complexType>

<!-- **************************************************** -->

  <xsd:complexType name="servletType">
    <xsd:annotation>
      <xsd:documentation>

        The servletType is used to declare a servlet.
        It contains the declarative data of a
        servlet. If a jsp-file is specified and the load-on-startup
        element is present, then the JSP should be pre-compiled and
        loaded.

        Used in: web-app

      </xsd:documentation>
    </xsd:annotation>

    <xsd:sequence>
      <xsd:group ref="j2ee:descriptionGroup"/>
      <xsd:element name="servlet-name"
                   type="j2ee:servlet-nameType"/>
      <xsd:choice>
        <xsd:element name="servlet-class"
                     type="j2ee:fully-qualified-classType">
          <xsd:annotation>
            <xsd:documentation>

              The servlet-class element contains the fully
              qualified class name of the servlet.

            </xsd:documentation>
          </xsd:annotation>
        </xsd:element>

        <xsd:element name="jsp-file"
                     type="j2ee:jsp-fileType"/>

      </xsd:choice>

      <xsd:element name="init-param"
                   type="j2ee:param-valueType"
                   minOccurs="0" maxOccurs="unbounded"/>
      <xsd:element name="load-on-startup"
                   type="j2ee:xsdIntegerType"
                   minOccurs="0">
        <xsd:annotation>
          <xsd:documentation>

            The load-on-startup element indicates that this
            servlet should be loaded (instantiated and have
            its init() called) on the start-up of the web
            application. The optional contents of these
            element must be an integer indicating the order in
            which the servlet should be loaded. If the value
            is a negative integer, or the element is not
            present, the container is free to load the servlet
            whenever it chooses. If the value is a positive
            integer or 0, the container must load and
            initialize the servlet as the application is
            deployed. The container must guarantee that
            servlets marked with lower integers are loaded
            before servlets marked with higher integers. The
            container may choose the order of loading of
            servlets with the same load-on-start-up value.

          </xsd:documentation>
        </xsd:annotation>
      </xsd:element>
      <xsd:element name="run-as"
                   type="j2ee:run-asType"
                   minOccurs="0"/>
      <xsd:element name="security-role-ref"
                   type="j2ee:security-role-refType"
                   minOccurs="0" maxOccurs="unbounded"/>
    </xsd:sequence>
    <xsd:attribute name="id" type="xsd:ID"/>
  </xsd:complexType>

<!-- **************************************************** -->

  <xsd:complexType name="session-configType">
    <xsd:annotation>
      <xsd:documentation>

        The session-configType defines the session parameters
        for this web application.

        Used in: web-app

      </xsd:documentation>
    </xsd:annotation>

    <xsd:sequence>
      <xsd:element name="session-timeout"
                   type="j2ee:xsdIntegerType"
                   minOccurs="0">
        <xsd:annotation>
          <xsd:documentation>

            The session-timeout element defines the default
            session timeout interval for all sessions created
            in this web application. The specified timeout
            must be expressed in a whole number of minutes.
            If the timeout is 0 or less, the container ensures
            the default behaviour of sessions is never to time
            out. If this element is not specified, the container
            must set its default timeout period.

          </xsd:documentation>
        </xsd:annotation>
      </xsd:element>
    </xsd:sequence>
    <xsd:attribute name="id" type="xsd:ID"/>
  </xsd:complexType>

<!-- **************************************************** -->

  <xsd:complexType name="transport-guaranteeType">
    <xsd:annotation>
      <xsd:documentation>

        The transport-guaranteeType specifies that the communication
        between client and server should be NONE, INTEGRAL, or
        CONFIDENTIAL. NONE means that the application does not
        require any transport guarantees. A value of INTEGRAL means
        that the application requires that the data sent between the
        client and server be sent in such a way that it can't be
        changed in transit. CONFIDENTIAL means that the application
        requires that the data be transmitted in a fashion that
        prevents other entities from observing the contents of the
        transmission. In most cases, the presence of the INTEGRAL or
        CONFIDENTIAL flag will indicate that the use of SSL is
        required.

        Used in: user-data-constraint

      </xsd:documentation>
    </xsd:annotation>

    <xsd:simpleContent>
      <xsd:restriction base="j2ee:string">
        <xsd:enumeration value="NONE"/>
        <xsd:enumeration value="INTEGRAL"/>
        <xsd:enumeration value="CONFIDENTIAL"/>
      </xsd:restriction>
    </xsd:simpleContent>
  </xsd:complexType>

<!-- **************************************************** -->

  <xsd:complexType name="user-data-constraintType">
    <xsd:annotation>
      <xsd:documentation>

        The user-data-constraintType is used to indicate how
        data communicated between the client and container should be
        protected.

        Used in: security-constraint

      </xsd:documentation>
    </xsd:annotation>

    <xsd:sequence>
      <xsd:element name="description"
                   type="j2ee:descriptionType"
                   minOccurs="0"
                   maxOccurs="unbounded"/>
      <xsd:element name="transport-guarantee"
                   type="j2ee:transport-guaranteeType"/>
    </xsd:sequence>
    <xsd:attribute name="id" type="xsd:ID"/>
  </xsd:complexType>

<!-- **************************************************** -->

  <xsd:complexType name="war-pathType">
    <xsd:annotation>
      <xsd:documentation>

        The elements that use this type designate a path starting
        with a "/" and interpreted relative to the root of a WAR
        file.

      </xsd:documentation>
    </xsd:annotation>
    <xsd:simpleContent>
      <xsd:restriction base="j2ee:string">
        <xsd:pattern value="/.*"/>
      </xsd:restriction>
    </xsd:simpleContent>
  </xsd:complexType>

<!-- **************************************************** -->

  <xsd:simpleType name="web-app-versionType">
    <xsd:annotation>
      <xsd:documentation>

        This type contains the recognized versions of
        web-application supported. It is used to designate the
        version of the web application.

      </xsd:documentation>
    </xsd:annotation>
    <xsd:restriction base="xsd:token">
      <xsd:enumeration value="2.4"/>
    </xsd:restriction>
  </xsd:simpleType>

<!-- **************************************************** -->

  <xsd:complexType name="web-appType">

    <xsd:choice minOccurs="0" maxOccurs="unbounded">
      <xsd:group ref="j2ee:descriptionGroup"/>
      <xsd:element name="distributable"
                   type="j2ee:emptyType"/>
      <xsd:element name="context-param"
                   type="j2ee:param-valueType">

        <xsd:annotation>
          <xsd:documentation>

            The context-param element contains the declaration
            of a web application's servlet context
            initialization parameters.

          </xsd:documentation>
        </xsd:annotation>
      </xsd:element>

      <xsd:element name="filter"
                   type="j2ee:filterType"/>
      <xsd:element name="filter-mapping"
                   type="j2ee:filter-mappingType"/>
      <xsd:element name="listener"
                   type="j2ee:listenerType"/>
      <xsd:element name="servlet"
                   type="j2ee:servletType"/>
      <xsd:element name="servlet-mapping"
                   type="j2ee:servlet-mappingType"/>
      <xsd:element name="session-config"
                   type="j2ee:session-configType"/>
      <xsd:element name="mime-mapping"
                   type="j2ee:mime-mappingType"/>
      <xsd:element name="welcome-file-list"
                   type="j2ee:welcome-file-listType"/>
      <xsd:element name="error-page"
                   type="j2ee:error-pageType"/>
      <xsd:element name="jsp-config"
                   type="j2ee:jsp-configType"/>
      <xsd:element name="security-constraint"
                   type="j2ee:security-constraintType"/>
      <xsd:element name="login-config"
                   type="j2ee:login-configType"/>
      <xsd:element name="security-role"
                   type="j2ee:security-roleType"/>
      <xsd:group ref="j2ee:jndiEnvironmentRefsGroup"/>
      <xsd:element name="message-destination"
                   type="j2ee:message-destinationType"/>
      <xsd:element name="locale-encoding-mapping-list"
                   type="j2ee:locale-encoding-mapping-listType"/>
    </xsd:choice>

    <xsd:attribute name="version"
                   type="j2ee:web-app-versionType"
                   use="required"/>
    <xsd:attribute name="id" type="xsd:ID"/>
  </xsd:complexType>

<!-- **************************************************** -->

  <xsd:complexType name="web-resource-collectionType">
    <xsd:annotation>
      <xsd:documentation>

        The web-resource-collectionType is used to identify a subset
        of the resources and HTTP methods on those resources within
        a web application to which a security constraint applies. If
        no HTTP methods are specified, then the security constraint
        applies to all HTTP methods.

        Used in: security-constraint

      </xsd:documentation>
    </xsd:annotation>

    <xsd:sequence>
      <xsd:element name="web-resource-name"
                   type="j2ee:string">
        <xsd:annotation>
          <xsd:documentation>

            The web-resource-name contains the name of this web
            resource collection.

          </xsd:documentation>
        </xsd:annotation>
      </xsd:element>
      <xsd:element name="description"
                   type="j2ee:descriptionType"
                   minOccurs="0"
                   maxOccurs="unbounded"/>
      <xsd:element name="url-pattern"
                   type="j2ee:url-patternType"
                   maxOccurs="unbounded"/>
      <xsd:element name="http-method"
                   type="j2ee:http-methodType"
                   minOccurs="0" maxOccurs="unbounded"/>
    </xsd:sequence>
    <xsd:attribute name="id" type="xsd:ID"/>
  </xsd:complexType>

<!-- **************************************************** -->

  <xsd:complexType name="welcome-file-listType">
    <xsd:annotation>
      <xsd:documentation>

        The welcome-file-list contains an ordered list of welcome
        files elements.

        Used in: web-app

      </xsd:documentation>
    </xsd:annotation>

    <xsd:sequence>
      <xsd:element name="welcome-file"
                   type="xsd:string"
                   maxOccurs="unbounded">
        <xsd:annotation>
          <xsd:documentation>

            The welcome-file element contains file name to use
            as a default welcome file, such as index.html

          </xsd:documentation>
        </xsd:annotation>
      </xsd:element>
    </xsd:sequence>
    <xsd:attribute name="id" type="xsd:ID"/>
  </xsd:complexType>

</xsd:schema>


其中定义了各种标签,选不熟悉的标签解释下:

login-config:

用来指定所使用的验证方法、领域名和表单验证机制所需的特性。login-config子元素的描述如下: 

● auth-method指定验证方法。它的值为下面的一个:BASIC、DIGEST、FORM或 CLIENT-CERT  

● realm-name指定HTTP Basic验证中使用的领域名。  

● form-login-config指定基于表单的登录中应该使用的登录页面和出错页面。如果没有使用基于表单的验证,则忽略这些元素。这个元素的定义如下,其中form-login-page用于指定显示登录页面的资源路径, form-error-page则用于指定用户登录失败时显示出错页面的资源路径。这两个页面路径都必须以a/开始,并与应用目录相对应。  <!ELEMENT form-login-config (form-login-page, form-error-page)>  

<!ELEMENT form-login-page (#PCDATA)>  

<!ELEMENT form-error-page (#PCDATA)>

<login-config>
        <auth-method>FORM</auth-method>
        <form-login-config>
            <form-login-page>/login.html</form-login-page>
            <form-error-page>/error.jsp</form-error-page>
        </form-login-config>
    </login-config>


jsp-config:


<jsp-config> 包括<taglib> 和<jsp-property-group> 两个子元素。
    
    其中<taglib>元素在JSP 1.2时就已经存在;而<jsp-property-group>是JSP 2.0 新增的元素。
    <jsp-property-group>元素主要有八个子元素,它们分别为:
    
    1.<description>:设定的说明;
    2.<display-name>:设定名称;
    3.<url-pattern>:设定值所影响的范围,如:/CH2 或 /*.jsp;
    4.<el-ignored>:若为true,表示不支持EL 语法;
    5.<scripting-invalid>:若为true,表示不支持<% scripting %>语法;
    6.<page-encoding>:设定JSP 网页的编码;
    7.<include-prelude>:设置JSP 网页的抬头,扩展名为.jspf;
    8.<include-coda>:设置JSP 网页的结尾,扩展名为.jspf。


一个简单的<jsp-config>元素完整配置:

<jsp-config>
    <taglib>
        <taglib-uri>Taglib</taglib-uri>
        <taglib-location>/WEB-INF/tlds/MyTaglib.tld</taglib-location>
    </taglib>
    <jsp-property-group>
        <description>Special property group for JSP Configuration JSP example.</description>
        <display-name>JSPConfiguration</display-name>
        <url-pattern>/jsp/* </url-pattern>
        <el-ignored>true</el-ignored>
        <page-encoding>GB2312</page-encoding>
        <scripting-invalid>true</scripting-invalid>
        <include-prelude>/include/prelude.jspf</include-prelude>
        <include-coda>/include/coda.jspf</include-coda>
    </jsp-property-group>
</jsp-config>

jsp中通过<%@ taglib prefix="自定义标签的short-name" uri="Taglib"%>来引用


以下转自http://www.cnblogs.com/hzj-/articles/1689836.html

<context-param>与<init-param>的区别与作用

<context-param>的作用:
web.xml的配置中<context-param>配置作用
1. 启动一个WEB项目的时候,容器(如:Tomcat)会去读它的配置文件web.xml.读两个节点: <listener></listener> 和 <context-param></context-param>
2.紧接着,容器创建一个ServletContext(上下文),这个WEB项目所有部分都将共享这个上下文.
3.容器将<context-param></context-param>转化为键值对,并交给ServletContext.
4.容器创建<listener></listener>中的类实例,即创建监听.
5.在监听中会有contextInitialized(ServletContextEvent args)初始化方法,在这个方法中获得ServletContext = ServletContextEvent.getServletContext();
context-param的值 = ServletContext.getInitParameter("context-param的键");
6.得到这个context-param的值之后,你就可以做一些操作了.注意,这个时候你的WEB项目还没有完全启动完成.这个动作会比所有的Servlet都要早.
换句话说,这个时候,你对<context-param>中的键值做的操作,将在你的WEB项目完全启动之前被执行.
7.举例.你可能想在项目启动之前就打开数据库.
那么这里就可以在<context-param>中设置数据库的连接方式,在监听类中初始化数据库的连接.
8.这个监听是自己写的一个类,除了初始化方法,它还有销毁方法.用于关闭应用前释放资源.比如说数据库连接的关闭.
如:
<!-- 加载spring的配置文件 -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext.xml,/WEB-INF/act ion-servlet.xml,/WEB-
INF/jason-servlet.xml</param-value>
</context-param>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
又如: --->自定义context-param,且自定义listener来获取这些信息
<context-param>
    <param-name>urlrewrite</param-name>
    <param-value>false</param-value>
</context-param>
<context-param>
    <param-name>cluster</param-name>
    <param-value>false</param-value>
</context-param>
<context-param>
    <param-name>servletmapping</param-name>
    <param-value>*.bbscs</param-value>
</context-param>
<context-param>
    <param-name>poststoragemode</param-name>
    <param-value>1</param-value>
</context-param>
<listener>
    <listener-class>com.laoer.bbscs.web.servlet.SysListener</listener-class>
</listener>
public class SysListener extends HttpServlet implements ServletContextListener {
private static final Log logger = LogFactory.getLog(SysListener.class);
public void contextDestroyed(ServletContextEvent sce) {
   //用于在容器关闭时,操作
}
//用于在容器开启时,操作
public void contextInitialized(ServletContextEvent sce) {
   String rootpath = sce.getServletContext().getRealPath("/");
   System.out.println("-------------rootPath:"+rootpath);
   if (rootpath != null) {
    rootpath = rootpath.replaceAll(" \\\\", "/");
   } else {
    rootpath = "/";
   }
   if (!rootpath.endsWith("/")) {
    rootpath = rootpath + "/";
   }
   Constant.ROOTPATH = rootpath;
   logger.info("Application Run Path:" + rootpath);
   String urlrewrtie = sce.getServletContext().getInitParameter("urlrewrite");
   boolean burlrewrtie = false;
   if (urlrewrtie != null) {
    burlrewrtie = Boolean.parseBoolean(urlrewrtie);
   }
   Constant.USE_URL_REWRITE = burlrewrtie;
   logger.info("Use Urlrewrite:" + burlrewrtie);
   其它略之....
   }
}
   /*最终输出
   -------------rootPath:D:\tomcat_bbs\webapps\BBSCS_8_0_3\
   2009-06-09 21:51:46,526 [com.laoer.bbscs.web.servlet.SysListener]-[INFO]
Application Run Path:D:/tomcat_bbs/webapps/BBSCS_8_0_3/
   2009-06-09 21:51:46,526 [com.laoer.bbscs.web.servlet.SysListener]-[INFO]
Use Urlrewrite:true
   2009-06-09 21:51:46,526 [com.laoer.bbscs.web.servlet.SysListener]-[INFO]
Use Cluster:false
   2009-06-09 21:51:46,526 [com.laoer.bbscs.web.servlet.SysListener]-[INFO]
SERVLET MAPPING:*.bbscs
   2009-06-09 21:51:46,573 [com.laoer.bbscs.web.servlet.SysListener]-[INFO]
Post Storage Mode:1
   */
context-param和init-param区别
web.xml里面可以定义两种参数:
(1)application范围内的参数,存放在servletcontext中,在web.xml中配置如下:
<context-param>
           <param-name>context/param</param-name>
           <param-value>avalible during application</param-value>
</context-param>
(2)servlet范围内的参数,只能在servlet的init()方法中取得,在web.xml中配置如下:
<servlet>
    <servlet-name>MainServlet</servlet-name>
    <servlet-class>com.wes.controller.MainServlet</servlet-class>
    <init-param>
       <param-name>param1</param-name>
       <param-value>avalible in servlet init()</param-value>
    </init-param>
    <load-on-startup>0</load-on-startup>
</servlet>
在servlet中可以通过代码分别取用:
package com.wes.controller;
imp ort javax.servlet.ServletException;
imp ort javax.servlet.http.HttpServlet;
public class MainServlet extends HttpServlet ...{
    public MainServlet() ...{
        super();
     }
    public void init() throws ServletException ...{
         System.out.println("下面的两个参数param1是在servlet中存放的");
         System.out.println(this.getInitParameter("param1"));
         System.out.println("下面的参数是存放在servletcontext中的");
        System.out.println(getServletContext().getInitParameter("context/param"));
      }
}
第一种参数在servlet里面可以通过getServletContext().getInitParameter("context/param")得到
第二种参数只能在servlet的init()方法中通过this.getInitParameter("param1")取得.



  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值