web-app:必备,出现在首尾

上下文参数:声明应用范围内的初始化参数。
<context-param>
   <param-name>ContextParameter</para-name>
   <param-value>test</param-value>
   <description>It is a test parameter.</description>
</context-param>

<display-name></display-name>定义了WEB应用的名字
<description></description> 声明WEB应用的描述信息

<welcome-file-list></welcome-file-list> 指示服务器在收到引用一个目录名而不是文件名的URL时,使用哪个文件

错误页:使用错误信息

<error-page>
       <error-code>500</error-code>
       <location>/error.jsp</location>
 </error-page>

通过异常的类型配置error-page
<error-page>
       <exception-type>java.lang.NullException</exception-type>
       <location>/error.jsp</location>
</error-page>

Web应用图标:指出IDE和GUI工具用来表示Web应用的大图标和小图标
<icon>
<small-icon>/p_w_picpaths/app_small.gif</small-icon>
<large-icon>/p_w_picpaths/app_large.gif</large-icon>
</icon>

过滤器配置:将一个名字与一个实现javaxs.servlet.Filter接口的类相关联。
<filter>
       <filter-name>setCharacterEncoding</filter-name>
       <filter-class>com.myTest.setCharacterEncodingFilter</filter-class>
       <init-param>
           <param-name>encoding</param-name>
           <param-value>GB2312</param-value>
       </init-param>
</filter>
<filter-mapping>
       <filter-name>setCharacterEncoding</filter-name>
       <url-pattern>/*</url-pattern>
</filter-mapping>

监听器配置
<listener>
     <listerner-class>listener.SessionListener</listener-class>
</listener>

Servlet配置
  基本配置
  <servlet>
     <servlet-name>snoop</servlet-name>
     <servlet-class>SnoopServlet</servlet-class>
  </servlet>
  <servlet-mapping>
     <servlet-name>snoop</servlet-name>
     <url-pattern>/snoop</url-pattern>
  </servlet-mapping>
  高级配置
  <servlet>
     <servlet-name>snoop</servlet-name>
     <servlet-class>SnoopServlet</servlet-class>
     <init-param>
        <param-name>foo</param-name>
        <param-value>bar</param-value>
     </init-param>
     <run-as>
        <description>Security role for anonymous access</description>
        <role-name>tomcat</role-name>
     </run-as>
  </servlet>
  <servlet-mapping>
     <servlet-name>snoop</servlet-name>
     <url-pattern>/snoop</url-pattern>
  </servlet-mapping>

<load-on-startup></load-on-startup>指定当Web应用启动时,装载Servlet的次序。 当值为正数或零时:Servlet容器先加载数值小的servlet,再依次加载其他数值大的servlet. 当值为负或未定义:Servlet容器将在Web客户首次访问这个servlet时加载它

会话超时配置(单位为分钟)<session-config>

     <session-timeout>120</session-timeout>
  </session-config>

MIME类型配置
  <mime-mapping>
     <extension>htm</extension>
     <mime-type>text/html</mime-type>
  </mime-mapping>

资源管理对象配置
  <resource-env-ref>
      <resource-env-ref-name>jms/StockQueue</resource-env-ref-name>
  </resource-env-ref>

资源工厂配置
  <resource-ref>
      <res-ref-name>mail/Session</res-ref-name>
      <res-type>javax.mail.Session</res-type>
      <res-auth>Container</res-auth>
  </resource-ref>
  配置数据库连接池就可在此配置:
  <resource-ref>
      <description>JNDI JDBC DataSource of shop</description>
      <res-ref-name>jdbc/sample_db</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
  </resource-ref>

安全限制配置
  <security-constraint>
     <display-name>Example Security Constraint</display-name>
     <web-resource-collection>
        <web-resource-name>Protected Area</web-resource-name>
        <url-pattern>/jsp/security/protected/*</url-pattern>
        <http-method>DELETE</http-method>
        <http-method>GET</http-method>
        <http-method>POST</http-method>
        <http-method>PUT</http-method>
     </web-resource-collection>
     <auth-constraint>
       <role-name>tomcat</role-name>
       <role-name>role1</role-name>
     </auth-constraint>
  </security-constraint>
16、登陆验证配置
  <login-config>
    <auth-method>FORM</auth-method>
    <realm-name>Example-Based Authentiation Area</realm-name>
    <form-login-config>
       <form-login-page>/jsp/security/protected/login.jsp</form-login-page>
       <form-error-page>/jsp/security/protected/error.jsp</form-error-page>
    </form-login-config>
  </login-config>
17、安全角色:security-role元素给出安全角色的一个列表,这些角色将出现在servlet元素内的security-role-ref元素的role-name子元素中。
   分别地声明角色可使高级IDE处理安全信息更为容易。
<security-role>
    <role-name>tomcat</role-name>
</security-role>
18、Web环境参数:env-entry元素声明Web应用的环境项
<env-entry>
    <env-entry-name>minExemptions</env-entry-name>
    <env-entry-value>1</env-entry-value>
    <env-entry-type>java.lang.Integer</env-entry-type>
</env-entry>
19、EJB 声明
<ejb-ref>
    <description>Example EJB reference</decription>
    <ejb-ref-name>ejb/Account</ejb-ref-name>
    <ejb-ref-type>Entity</ejb-ref-type>
    <home>com.mycompany.mypackage.AccountHome</home>
    <remote>com.mycompany.mypackage.Account</remote>
</ejb-ref>
20、本地EJB声明
<ejb-local-ref>
    <description>Example Loacal EJB reference</decription>
    <ejb-ref-name>ejb/ProcessOrder</ejb-ref-name>
    <ejb-ref-type>Session</ejb-ref-type>
    <local-home>com.mycompany.mypackage.ProcessOrderHome</local-home>
    <local>com.mycompany.mypackage.ProcessOrder</local>
</ejb-local-ref>
21、配置DWR
<servlet>
     <servlet-name>dwr-invoker</servlet-name>
     <servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class>
</servlet>
<servlet-mapping>
     <servlet-name>dwr-invoker</servlet-name>
     <url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
22、配置Struts
   <display-name>Struts Blank Application</display-name>
   <servlet>
       <servlet-name>action</servlet-name>
       <servlet-class>
           org.apache.struts.action.ActionServlet
       </servlet-class>
       <init-param>
           <param-name>detail</param-name>
           <param-value>2</param-value>
       </init-param>
       <init-param>
           <param-name>debug</param-name>
           <param-value>2</param-value>
       </init-param>
       <init-param>
           <param-name>config</param-name>
           <param-value>/WEB-INF/struts-config.xml</param-value>
       </init-param>
       <init-param>
           <param-name>application</param-name>
           <param-value>ApplicationResources</param-value>
       </init-param>
       <load-on-startup>2</load-on-startup>
   </servlet>
   <servlet-mapping>
       <servlet-name>action</servlet-name>
       <url-pattern>*.do</url-pattern>
   </servlet-mapping>
   <welcome-file-list>
       <welcome-file>index.jsp</welcome-file>
   </welcome-file-list>

   <!-- Struts Tag Library Descriptors -->
   <taglib>
       <taglib-uri>struts-bean</taglib-uri>
       <taglib-location>/WEB-INF/tld/struts-bean.tld</taglib-location>
   </taglib>
   <taglib>
       <taglib-uri>struts-html</taglib-uri>
       <taglib-location>/WEB-INF/tld/struts-html.tld</taglib-location>
   </taglib>
   <taglib>
   <taglib-uri>struts-nested</taglib-uri>
   <taglib-location>/WEB-INF/tld/struts-nested.tld</taglib-location>
   </taglib>
   <taglib>
       <taglib-uri>struts-logic</taglib-uri>
       <taglib-location>/WEB-INF/tld/struts-logic.tld</taglib-location>
   </taglib>
   <taglib>
       <taglib-uri>struts-tiles</taglib-uri>
       <taglib-location>/WEB-INF/tld/struts-tiles.tld</taglib-location>
   </taglib>
23、配置Spring(基本上都是在Struts中配置的)

  <!-- 指定spring配置文件位置 -->
  <context-param>
     <param-name>contextConfigLocation</param-name>
     <param-value>
      <!--加载多个spring配置文件 -->
       /WEB-INF/applicationContext.xml, /WEB-INF/action-servlet.xml
     </param-value>
  </context-param>

  <!-- 定义SPRING监听器,加载spring -->

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<listener>
    <listener-class>
      org.springframework.web.context.request.RequestContextListener
    </listener-class>
</listener>