here's my code:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.WebServlet;
@WebServlet(name="HelloWorld",urlPatterns={"/HW"})
public class HelloWorld extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println("Hello Programmers!!! ");
}
}
to access it on Tomcat, i goto :
localhost:8080/examples/HW
so i guess @WebServlet is supposedly required to do the mapping for a servlet other wise we could have done manually in the web.xml file in the WEB-INF directory
and oh, my directory tree:
tomcat-->webapps--->examples-->WEB-INF-->classes-->HelloWorld.class
so my HelloWorld is placed in classes folder as you can see
and you have seen my code and my use of @WebServlet annotation.
but when i goto localhost:8080/examples/HW i get 404 error
The requested resource (/examples/HW) is not available.
what am i doing wrong??
tomcat - 7.0.11
servlet version - dunno.. shouldn't it be latest coz i'm using the servlet-api.jar provided by tomcat. so if tomcat is 7.x,so should servlet be latest too right?
i mean its not giving any error about the annotation tag at compilation