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

一:schema

1.第一行定义了该web.xml的版本描述和语言编码方式(1.0和UTF-8)。
2.第二行<web-app></web-app>是web.xml的根节点。xml的schema都必须放在xml文件的根标签上。同理,其他类型的xml的schema也都必须放在根标签上。

3.xml的schema的命名规则

a.xmlns:xsi全称xml name space:xml schema instance(xml命名空间:xml的schema的实例)而里面的值的引用相当于url。

b.xmlns:web是指向web项目的统一标准。

c.xsi:schemaLocation是xml的schema的实例的引用位置(要使用它必须先指定xmlns:xsi)。

4.一旦拥有了可用的XML Shema实例命名空间,您就可以使用schemaLocation属性了。此属性有两个值。第一个值是需要使用的命名空间。第二个值是供命名空间使用的XML schema的位置.

二:其他元素(都放在<web-app></web-app>之间)

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

1.<discription></discription> 是对站台的描述
   <display-name></display-name> 定义站台的名称
   <distributable/> 是指定该站台是否可分布式处理

2.<context-param></context-param> 用来设定web站台的环境参数,它包含两个子元素:
     <param-name></param-name> 用来指定参数的名称
     <param-value></param-value> 用来设定参数值

栗子:<context-param>

<param-name>para</param-name>

<param-value>hello</param-value>

</context-param>

在此设定的参数,可以在servlet中用 getServletContext().getInitParameter("param") 来取得。

3.<filter></filter> 是用来声明filter的相关设定,它包含以下子元素:

<filter-name></filter-name> 这当然就是指定filter的名字

<filter-class></filter-class> 这是用来定义filter的类的名称

<init-param></init-param> 用来定义参数,它有两个子元素:

<param-name></param-name> 用来指定参数的名称

<param-value></param-value> 用来设定参数值

栗子: <filter>

<filter-name>setCharacterEncoding</filter-name>

<filter-class>com.myTest.setCharacterEncodingFilter</filter-class>

<init-param>

<param-name>encoding</param-name>

<param-value>UTF-8</param-value>

</init-param>

</filter>

与<filter></filter>同时使用的是<filter-mapping></filter-mapping> 用来定义filter所对应的URL,它有两个子元素:

<filter-name></filter-name> 指定filter的名字

<url-pattern></url-pattern> 指定filter所对应的URL

栗子: <filter-mapping>

<filter-name>setCharacterEncoding</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

4.<listener></listener> 用来设定Listener接口,它的主要子元素为

<listener-class></listener-class> 定义Listener的类名称

栗子: <listener>

<listener-class>com.myTest.ContextListener</listener-class>

</listener>

5.<servlet></servlet> 用来声明一个servlet的数据,主要有以下子元素:

<servlet-name></servlet-name> 指定servlet的名称

<servlet-class></servlet-class> 指定servlet的类名称

<load-on-startup>4<load-on-startup>指定servlet的加载顺序(整数或零,从小到大一次加载,值为负或未定义时,在首次访问时加载)

<jsp-file></jsp-file> 指定web站台中的某个JSP网页的完整路径

<init-param></init-param> 用来定义参数,和前面的<init-param>差不多

同样,与<servlet></servlet>一起使用的是<servlet-mapping></servlet-mapping> 用来定义servlet所对应的URL,包含两个子元素:

<servlet-name></servlet-name> 指定servlet的名称

<url-pattern></url-pattern> 指定servlet所对应的URL

栗子: <servlet>

<servlet-name>ShoppingServlet</servlet-name>

<servlet-class>com.myTest.ShoppingServlet</servlet-class>

<load-on-startup>4<load-on-startup>

</servlet>

<servlet-mapping>

<servlet-name>ShoppingServlet</servlet-name>

<url-pattern>/shop/ShoppingServlet</url-pattern>

</servlet-mapping>

6.<session-config></session-config> 用来定义web站台中的session参数,包含一个子元素:
    <session-timeout></session-timeout> 用来定义这个web站台所有session的有效期限,单位为分钟

7.<mime-mapping></mime-mapping> 定义某一个扩展名和某一个MIME Type做对映,包含两个子元素:

<extension></extension> 扩展名的名称

<mime-type></mime-type> MIME格式

栗子: <mime-mapping>

<extension>doc</extension>

<mime-type>application/vnd.ms-word</mime-type>

</mime-mapping>

<mime-mapping>

<extension>xls</extension>

<mime-type>application/vnd.ms-excel</mime-type>

</mime-mapping>

8.<welcome-file-list></welcom-file-list> 用来定义首页的列单,包含一个子元素:

<welcome-file></welcome-file> 指定首页的文件名称

栗子: <welcome-file-list>

<welcome-file>index.jsp</welcome-file>

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

</welcom-file-list>

9.<error-page></error-page> 用来处理错误代码或异常的页面,有三个子元素:

<error-code></error-code> 指定错误代码

<exception-type></exception-type> 指定一个JAVA异常类型

<location></location> 指定在web站台内的相关资源路径

栗子: <error-page>

<error-code>404</error-code>

<location>/error404.jsp</location>

</error-page>

<error-page>

<exception-type>java.lang.Exception</exception-type>

<location>/exception.jsp</location>

</error-page>

10.<taglib></taglib> 用来设定JSP网页所用到的Tag Library路径,有两个子元素:

<taglib-uri></taglib-uri> 定义TLD文件的URI,在JSP网页中用taglib指令便可取得该URI的TLD文件

<taglib-location></taglib-location> 指定TLD文件相对于web站台的存放位置

栗子: <taglib>

<taglib-uri>myTaglib</taglib-uri>

<taglib-location>/WEB-INF/tlds/MyTaglib.tld</taglib-location>

</taglib>

11.<resource-ref></resource-ref> 定义利用JNDI取得站台可利用的资源,有五个子元素:

<description></description> 资源说明

<rec-ref-name></rec-ref-name> 资源名称

<res-type></res-type> 资源种类

<res-auth></res-auth> 资源经由Application或Container来许可

<res-sharing-scope></res-sharing-scope> 资源是否可以共享,有Shareable和Unshareable两个值,默认为Shareable

栗子,配置数据库连接池就可在此配置:

<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>

spring 的web.xml的更多相关文章

  1. J2EE进阶(五)Spring在web.xml中的配置

     J2EE进阶(五)Spring在web.xml中的配置 前言 在实际项目中spring的配置文件applicationcontext.xml是通过spring提供的加载机制自动加载到容器中.在web ...

  2. 使用Spring时web.xml中的配置

    使用Spring时web.xml中的配置: <?xml version="1.0" encoding="UTF-8"?> <web-app x ...

  3. Spring 入门 web.xml配置详解

    Spring 入门 web.xml配置详解 https://www.cnblogs.com/cczz_11/p/4363314.html https://blog.csdn.net/hellolove ...

  4. 深入Spring之web.xml

    针对web.xml我打算从以下几点进行解析: 1.ContextLoaderListener: 启动Web容器时,自动装配ApplicationContext的配置信息. 2.RequestConte ...

  5. Spring与web.xml

    出处:http://blog.csdn.net/u010796790 在web.xml配置监听器 ContextLoaderListener (listener-class) ContextLoade ...

  6. spring在web.xml中的配置

    在实际项目中spring的配置文件applicationcontext.xml是通过spring提供的加载机制,自动加载的容器中去,在web项目中,配置文件加载到web容器中进行解析,目前,sprin ...

  7. Spring MVC Web.xml配置

    Web.xml spring&spring mvc 在web.xml中定义contextConfigLocation参数,Spring会使用这个参数去加载所有逗号分隔的xml文件,如果没有这个 ...

  8. spring 在web.xml 里面如何使用多个xml配置文件

    1, 在web.xml中定义 contextConfigLocation参数.spring会使用这个参数加载.所有逗号分割的xml.如果没有这个参数,spring默认加载web-inf/applica ...

  9. Spring配置文件web.xml关于拦截

    1.<!-- 加载springMVC --><servlet><servlet-name>dispater</servlet-name><serv ...

随机推荐

  1. 【转】Servlet 生命周期、工作原理

    Servlet 生命周期:Servlet 加载--->实例化--->服务--->销毁. init():在Servlet的生命周期中,仅执行一次init()方法.它是在服务器装入Ser ...

  2. redis服务器学习一

    一:什么是redis服务器 redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zs ...

  3. jquery中Get方法请求接口

    $.ajax( { url: apiUrl + '/api/Code/GetCodeProductInfo', type: 'GET', //Header头部添加Token参数 beforeSend: ...

  4. 内存(RAM或ROM)和FLASH存储的真正区别总结

    转载自:http://blog.csdn.net/liangkaiyang/article/details/59556531.什么是内存     什么是内存呢?在计算机的组成结构中,有一个很重要的部分 ...

  5. 【netcore基础】ubuntu 16.04 搭建.net core 2.1 linux 运行环境 nginx反向代理 supervisor配置自启动

    今天来整理下 netcore 在 linux(ubuntu) 上的运行环境搭建 对应版本 ubuntu 16.04 .net core 2.1 nginx version: nginx/1.10.3 ...

  6. Qt自定义控件大全+designer源码

    抽空将自定义控件的主界面全部重写了一遍,采用左侧树状节点导航,看起来更精美高大上一点,后期准备单独做个工具专用每个控件的属性设计,其实qt自带的designer就具备这些功能,于是从qt4的源码中抽取 ...

  7. C#获取一个数组中的最大值、最小值、平均值

    C#获取一个数组中的最大值.最小值.平均值 1.给出一个数组 ,,,,,-,,,,}; 2.数组Array自带方法 本身是直接可以调用Min(),Max(),Average()方法来求出 最小值.最大 ...

  8. [原]openstack-kilo--issue(二十三)虚拟机状态错误power_status为shutdonw或者vm_status为error

    问题点:虚拟机由于存储不足出现了错误标识 主要显示为状态错误: 1)  vm_status 显示为 error 2) power_status 显示为 shutdown 解决方案: 更改表 nova. ...

  9. 关于windows 下每次打开IE 8都弹出欢迎使用Internet Explorer 8 弹窗的关闭方法

    今天笔者在安装完windows 操作系统后,发现了一个问题,即每次打开IE 8浏览器,都会弹出一个欢迎界面: 弹窗标题为:设置windows Internet Explorer,具体内容如下图所示: ...

  10. Java高并发系列 — AQS

    只懂volatile和CAS是不是可以无视concurrent包了呢,发现一个好链接,继续死磕,第一日: 首先,我承认很多时候要去看源码才能更好搞懂一些事,但如果站在巨人肩膀上呢?有了大概思想源码看还 ...