We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,430 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

servlet mapping problem using @WebSerlvet annotation

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

1
Contributor
0
Replies
1
View
ronnieaka
Junior Poster in Training
63 posts since May 2009
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.0800 seconds using 2.76MB