今天看到书上对于Servlet3.0的讲解,结合自身遇到的问题总结如下:
1.首先确定你使用的Servlet 的版本,查看版本的方式有两种:
A -在tomcat安装文件下\lib下的servlet-api.jar和jsp-api.jar压缩文件(只针对Tomcat6.0以上),解压后找到对应的 META-INF文件夹下的MANIFEST.MF文件 打开后,看到
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.1 Created-By: 1.6.0_31-b05 (Sun Microsystems Inc.) X-Compile-Source-JDK: 1.6 X-Compile-Target-JDK: 1.6 Name: javax/servlet/ Specification-Title: Java API for ServletsSpecification-Version: 3.0 Specification-Vendor: Sun Microsystems, Inc. Implementation-Title: javax.servlet Implementation-Version: 3.0.FR Implementation-Vendor: Apache Software Foundation====================================================================
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.1 Created-By: 1.6.0_31-b05 (Sun Microsystems Inc.) X-Compile-Source-JDK: 1.6 X-Compile-Target-JDK: 1.6 Name: javax/servlet/jsp/ Specification-Title: Java API for JavaServer PagesSpecification-Version: 2.2 Specification-Vendor: Sun Microsystems, Inc. Implementation-Title: javax.servlet.jsp Implementation-Version: 2.2.FR Implementation-Vendor: Apache Software Foundation B ---在myeclipse中新建一web project ,选择这一项,然后再该项目下 找到 webroot-->WEB-INF-->web.xml ,打开web.xml文件,从文件中可以看出 Servlet的版本,
<?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>2.确定了Servlet的版本后,如果正在使用的是Servlet3.0,就可以直接使用@WebServlet(name="")进行Servlet的配置了,如果正在使用的Servlet 的版本不是3.0 ,需要手动地把servlet-api.jar复制到 webroot-->WEB-INF-->lib文件夹下。