This question already has an answer here:
I have a problem with my simple servlet that I am trying to run, Hello.java. I made it in eclipse, then placed the file it in the webapps/ServletTest/WEB-INF/classes folder and compiled it, creating the file Hello.class in the same folder. I then modified my web.xml file to map the servlet and tried to run it through the following address
http://localhost:8080/ServletTest/Hello However, this did not work, giving the following error
HTTP Status 404 -
type Status report
message
description The requested resource is not available. Apache Tomcat/7.0.42
The mapping in the web.xml file looks like this:
<servlet> <servlet-name>Hello</servlet-name> <servlet-class>Main.Hello</servlet-class> </servlet> <servlet-mapping> <servlet-name>Hello</servlet-name> <url-pattern>/Hello</url-pattern> </servlet-mapping> The code of the servlet:
package Main; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @WebServlet("/Hello") public class Hello extends HttpServlet { private static final long serialVersionUID = 1L; public Hello() { super(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { PrintWriter out = response.getWriter(); response.setContentType("text/html"); String path = request.getContextPath(); String ip = request.getRemoteAddr(); out.print("<html>" + "<title>Hello</title>" + "Hello World"+ "<br>" + "Your ip is: " + ip + "<br>" + "Your path is: " + path + "</html>"); } protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { } }