servlet版本与tomcat版本对应关系,各版本web.xml头信息写法

13 篇文章 0 订阅

Apache官方对各版本的解释:http://tomcat.apache.org/whichversion.html

Servlet SpecJSP SpecEL SpecWebSocket SpecJASPIC SpecApache Tomcat versionActual release revisionSupported Java Versions
4.0TBD (2.4?)TBD (3.1?)TBD (1.2?)1.19.0.x9.0.0.M9 (alpha)8 and later
3.12.33.01.11.18.5.x8.5.47 and later
3.12.33.01.1N/A8.0.x (superseded)8.0.35 (superseded)7 and later
3.02.22.21.1N/A7.0.x7.0.706 and later(7 and later for WebSocket)
2.52.12.1N/AN/A6.0.x6.0.455 and later
2.42.0N/AN/AN/A5.5.x (archived)5.5.36 (archived)1.4 and later
2.31.2N/AN/AN/A4.1.x (archived)4.1.40 (archived)1.3 and later
2.21.1N/AN/AN/A3.3.x (archived)3.3.2 (archived)1.1 and later

web.xml——version2.3——JDK1.3——Tomcat4.1

<?xml version="1.0" encoding="ISO-8859-1"?>  
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">  
<web-app>  
</web-app>

web.xml——version2.4——JDK1.4——Tomcat5.5

<?xml version="1.0" encoding="UTF-8"?>  
<web-app id="WebApp_9" version="2.4" 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">  
</web-app>

web.xml——version2.5——JDK5.0——Tomcat6.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_2_5.xsd"  
version="2.5">  
</web-app>

web.xml——version3.0——JDK6.0——Tomcat7.0

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

web.xml——version3.1——JDK7.0——Tomcat8.0,Tomcat8.5

<?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">
</web-app>
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Spring和Tomcat之间没有直接的对应关系,它们是不同的框架/工具。Spring是一个Java企业级开发框架,它提供了大量的组件和工具,可以帮助我们更快、更方便地开发Java应用程序。而Tomcat是一个开源的Java Servlet容器,它实现了Java Servlet和JavaServer Pages(JSP)规范,可以帮助我们部署和运行Java Web应用程序。 Servlet是Java Web开发中的重要组件,它可以接收HTTP请求并返回HTTP响应。不同版本Servlet有不同的写法。以下是各版本Servlet写法: - Servlet 2.5及以下版本: ```java public class MyServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // 处理GET请求 } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // 处理POST请求 } } ``` - Servlet 3.0及以上版本: ```java @WebServlet(name = "MyServlet", urlPatterns = {"/myServlet"}) public class MyServlet extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // 处理POST请求 } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // 处理GET请求 } } ``` 注意,Servlet 3.0及以上版本支持注解,可以通过@WebServlet注解来指定Servlet的名称和URL模式。而Servlet 2.5及以下版本需要在web.xml文件中配置Servlet

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值