@WebServlet注释不起作用

时间:2016-05-05 07:33:17

标签: java tomcat annotations servlet-3.0

我检查了以下可能的答案但未找到解决我的问题的方法  1. @WebServlet annotation with Tomcat 7
 2. @WebServlet annotation not recognized; init doesn't run
 3. @WebServlet annotation doesn't work with Tomcat 8

这是我的servlet-api.jar信息:

Manifest-Version: 1.0
Ant-Version: Apache Ant 1.8.4
Created-By: 1.6.0_37-b06 (Sun Microsystems Inc.)
X-Compile-Source-JDK: 1.6
X-Compile-Target-JDK: 1.6

Name: javax/servlet/
Specification-Title: Java API for Servlets
Specification-Version: 3.0
Specification-Vendor: Sun Microsystems, Inc.
Implementation-Title: javax.servlet
Implementation-Version: 3.0.FR
Implementation-Vendor: Apache Software Foundation

我的示例类代码:

import javax.servlet.annotation.WebServlet;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import javax.servlet.ServletException;                                                           
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/ProcessPayment")
public class ProcessPayment extends javax.servlet.http.HttpServlet{


public void doGet(HttpServletRequest req, HttpServletResponse res)throws IOException, ServletException{

        res.setContentType("text/html; charset=UTF-8");
        StringWriter sWriter = new StringWriter();  
        PrintWriter out = new PrintWriter(sWriter);         
try{
    SiteTemplate st     = new SiteTemplate();   
    PaymentDecorator pd = new PaymentDecorator();
    out.print(
        st.header(req)+st.headerButtons(req)+
            "<tr><td>"+
                pd.ccform(300,"6",1)+
            "</td></tr>"+
        st.footer());   

}catch(Exception ee){
        ErrorCheck ec = new ErrorCheck();
        ec.errorMsg("ERROR: GSW.ProcessPayment.java", ee);
}
res.getWriter().print(sWriter.toString());
}
}   

我的web.xml:

<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">

当我像http://127.0.0.1:7070/ProcessPayment那样访问它时,会显示以下消息:

  

HTTP状态404 - / ProcessPayment

     

输入状态报告

     

message / ProcessPayment

     

description请求的资源(/ ProcessPayment)不可用。

     

Apache Tomcat / 6.0.18

我更新了servlet-api,但发行说明文件中的Tomcat版本是:

  

Apache Tomcat版本6.0.18

请告知为什么@WebServlet注释不起作用?`

0 个答案:

没有答案