The 404 or Not Found HTTP response code indicates that the client was able to communicate with the server, but the server could not find the resource that was requested. And indeed...
First, according to your web.xml
, your Servlet is mapped on /greet
, and not /greetingservlet
. So why are you trying to access /greetingservlet
? Is this the name of your JSP? If yes, it's missing the .jsp
extension. If no, then you should probably use /greet
instead.
Second, your web.xml
doesn't look correct, the servlet-class
doesn't match the actual name of your servlet. It should be:
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<display-name>My First Web Application</display-name>
<servlet>
<servlet-name>one</servlet-name>
<servlet-class>com.acme.Greetingservlt</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>one</servlet-name>
<url-pattern>/greet</url-pattern>
</servlet-mapping>
</web-app>
Replace com.acme
with the real package of your servlet, if any(!). And redeploy the whole.
As a reminder, the URL to access the servlet is constructed like this:
http://localhost:8080/mywebapp/greet
A B C D
Where:
- A is the hostname where Tomcat is running (the local machine here)
- B is the port Tomcat is listening to (8080 is the default)
- C is the context path of your webapp (the name of the war by default)
- D is the pattern declared in the web.xml to invoke the servlet