3

I checked the following possible answers but not found fix for my problem
1. @WebServlet annotation with Tomcat 7
2. @WebServlet annotation not recognized; init doesn't run
3. @WebServlet annotation doesn't work with Tomcat 8

Here is my servlet-api.jar info:

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

My example class code:

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());
}
}   

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

When I access it like: http://127.0.0.1:7070/ProcessPayment then following message appears:

HTTP Status 404 - /ProcessPayment

type Status report

message /ProcessPayment

description The requested resource (/ProcessPayment) is not available.

Apache Tomcat/6.0.18

I updated servlet-api but my Tomcat version in Release Note file is:

Apache Tomcat Version 6.0.18

Please advise as to why @WebServlet annotation is not working?`

Community
  • 1
  • 1
LifeSaver
  • 138
  • 4
  • 10

0 Answers0