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>
web.xml是Java Web应用程序的配置文件,它位于WEB-INF目录下。在web.xml中可以配置Servlet、Filter、Listener、错误页面等。以下是一个简单的web.xml配置示例: ```xml <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> <display-name>MyWebApp</display-name> <!-- 配置Servlet --> <servlet> <servlet-name>HelloServlet</servlet-name> <servlet-class>com.example.HelloServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>HelloServlet</servlet-name> <url-pattern>/hello</url-pattern> </servlet-mapping> <!-- 配置Filter --> <filter> <filter-name>MyFilter</filter-name> <filter-class>com.example.MyFilter</filter-class> </filter> <filter-mapping> <filter-name>MyFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <!-- 配置Listener --> <listener> <listener-class>com.example.MyListener</listener-class> </listener> <!-- 配置错误页面 --> <error-page> <error-code>404</error-code> <location>/error.jsp</location> </error-page> </web-app> ``` 在上面的示例中,我们配置了一个名为HelloServlet的Servlet,它的Servlet类是com.example.HelloServlet,它的URL映射是/hello;还配置了一个名为MyFilter的Filter,它的Filter类是com.example.MyFilter,并且它匹配所有的URL;最后还配置了一个名为MyListener的Listener,它的Listener类是com.example.MyListener;最后还配置了一个404错误页面,它的地址是/error.jsp。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值