web.xml & web-fragment.xml (Servlet 2.3, 2.4, 2.5 + 3.0)模板

本文详细解析了web.xml的不同版本,并介绍了web-fragment.xml的使用方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

web.xml v2.3

Xml代码   收藏代码
  1. <?xml version="1.0" encoding="ISO-8859-1"?>  
  2. <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">  
  3.    
  4. <web-app>  
  5.    
  6. </web-app>  

 

web.xml v2.4

 

Xml代码   收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"   
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">  
  5.    
  6. </web-app>  

 

web.xml v2.5

 

Xml代码   收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2.    
  3. <web-app xmlns="http://java.sun.com/xml/ns/javaee"  
  4.    
  5. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  6.    
  7. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"  
  8.    
  9. version="2.5">  
  10.    
  11. </web-app>  

 

web.xml v3.0

 

Xml代码   收藏代码
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2.    
  3. <web-app  
  4.         version="3.0"  
  5.         xmlns="http://java.sun.com/xml/ns/javaee"  
  6.         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  7.         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">  
  8.    
  9. </web-app>  

 

 

web-fragment.xml

 

Xml代码   收藏代码
  1. <web-fragment xmlns="http://java.sun.com/xml/ns/javaee"  
  2.               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  3.               xsi:schemaLocation="  
  4.         http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-fragment_3_0.xsd" version="3.0">  
  5.    
  6. </web-fragment>  

 

&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt; &lt;web-app xmlns=&quot;http://xmlns.jcp.org/xml/ns/javaee&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; version=&quot;3.1&quot; xsi:schemaLocation=&quot;http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd&quot;&gt; &lt;context-param&gt; &lt;param-name&gt;metadata-complete&lt;/param-name&gt; &lt;param-value&gt;true&lt;/param-value&gt; &lt;/context-param&gt; &lt;servlet&gt; &lt;servlet-name&gt;exampleServlet&lt;/servlet-name&gt; &lt;servlet-class&gt;com.example.ExampleServlet&lt;/servlet-class&gt; &lt;/servlet&gt; &lt;servlet&gt; &lt;description&gt;generated-servlet&lt;/description&gt; &lt;servlet-name&gt;KuCun2 Servlet&lt;/servlet-name&gt; &lt;servlet-class&gt; org.springframework.web.servlet.DispatcherServlet &lt;/servlet-class&gt; &lt;init-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt;classpath:KuCun2-web-context.xml&lt;/param-value&gt; &lt;/init-param&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet&gt; &lt;description&gt;generated-resources-servlet&lt;/description&gt; &lt;servlet-name&gt;Resource Servlet&lt;/servlet-name&gt; &lt;servlet-class&gt; org.springframework.js.resource.ResourceServlet &lt;/servlet-class&gt; &lt;load-on-startup&gt;1&lt;/load-on-startup&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;exampleServlet&lt;/servlet-name&gt; &lt;url-pattern&gt;/example&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;Resource Servlet&lt;/servlet-name&gt; &lt;url-pattern&gt;/resources/*&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;listener&gt; &lt;listener-class&gt; org.springframework.web.context.ContextLoaderListener &lt;/listener-class&gt; &lt;/listener&gt; &lt;listener&gt; &lt;listener-class&gt; org.springframework.web.context.request.RequestContextListener &lt;/listener-class&gt; &lt;/listener&gt; &lt;context-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt;classpath:applicationContext.xml&lt;/param-value&gt; &lt;/context-param&gt; &lt;/web-app&gt;
最新发布
06-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值