1
votes

I have just started learning Java EE and recently got stuck to a problem. I am using eclipse Galileo and installed Tomcat 6.0 version. I needed to create a small Hello World servlet program for which I did the following.

  1. Created a dynamic web project (firstServlet) and inside Java Resource:src created a package.
  2. Under package I created a servlet by name 'HelloServlet' and url pattern as '/hello'.
  3. In HelloServlet I just override service method taking HttpServletRequest & HttpServletResponse parameters. Further I did response.getWriter.println("Hello Servlet") to print message on browser.
  4. Issue is when I hit the url as http://localhost:8080/firstServlet/hello, I am always getting a 404 error.

I did crosscheck that my Tomcat is using port 8080.

type Status report
message /firstProject/hello
description The requested resource (/firstProject/hello) is not available. Please Help.
1
Is your servlet mapped by web.xml or by @WebServlet? - Diogo Moreira

1 Answers

0
votes

This is a simple issue indicating, that it is not finding the class file for the servlet, in the path given.

  1. Please make sure, you have it mapped in web.xml
  2. In the web.xml the servlet<> tag needs to have the class path in the servlet-class<> tag of the servlet. If it is in some package? it should be com.somePackage.hello
  3. Also, make sure that it does mentions the package properly, in the hello.java file.

This will solve your issue.