web.xml文件的schema头部声明

  为了省事每次写项目时总是从网上复制粘贴web.xml的头文件,也算是脑抽吧,记录一下, schema头部声明。相关文档说明下载:

http://www.oracle.com/webfolder/technetwork/jsc/xml/ns/javaee/index.html#7

  下载文件:web-app_4_0.xsd 具体版本号自行决定本文以4.0版本为例打开xsd文件,文本打开没格式,看的很是难受,我用的DreamWeaver打开的。Web.xml的schema由文档了解

这是Servlet 4.0部署描述符的XML Schema。部署描述符必须在“WEB-INF/web.xml”
中命名Web应用程序的war文件。 所有Servlet部署描述符必须使用Java EE指示
Web应用程序架构命名空间:http://xmlns.jcp.org/xml/ns/javaee
并通过指示架构的版本使用如下所示的version元素:
      <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="..."
      version="4.0">
      ...
</web-app>
实例文档可能指示已发布的版本,使用Java EE的xsi:schemaLocation属性的模式具
有以下位置的命名空间:http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd

  所以最终应写的头文件是:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
             http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
            version="4.0">
</web-app>

附赠3.1到2.4版本。。。。

1. Servlet 3.1

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
             http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
            version="3.1">  
</web-app>

2. Servlet 3.0

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
          http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
          version="3.0">    
</web-app>

3. Servlet 2.5

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
          http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
          version="2.5"> 
</web-app>

4. Servlet 2.4

<?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">
</web-app>

猜你喜欢

转载自blog.csdn.net/sliker/article/details/81605407