I am pretty new to tomcat6 application deployment. I am trying to deploy my helloworld severlet on tomcat6. But whenrver I use servlet url as http://192.168.2.10:8080/hello/HelloWorldExample2 , I am getting following error :
HTTP Status 404 – /hello/HelloWorldExample2
type Status report
message /hello/HelloWorldExample2
description The requested resource (/hello/HelloWorldExample2) is not available.
I have copied my servlet to /var/lib/tomcat6/webapps directory. Here are the contents of my webapp directory
ls -lR hello/*
hello/WEB-INF:
total 8
drwxr-xr-x 2 root root 4096 2010-11-23 17:07 classes
-rw-r–r– 1 root root 658 2010-11-23 17:41 web.xml
hello/WEB-INF/classes:
total 8
-rw-r–r– 1 root root 1725 2010-11-23 17:07 HelloWorldExample2.class
-rw-r–r– 1 root root 2532 2010-11-23 17:06 HelloWorldExample2.java
Here are the contents of my web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>HelloWorldExample2</display-name>
<servlet>
<servlet-name>HelloWorldExample2</servlet-name>
<servlet-class></servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorldExample2</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
</web-app>
I am not sure why I am unable to load servlet. Please help.
Your web.xml is incorrect. It’s missing the
<servlet-class>which should be the the full name of the class including package. It seems to beHelloWorldExample2from your directory structure.and you are using the
url-pattern/hello which means you should try with the URL in the browser as:http://192.168.2.10:8080/hello/hello
i.e. the format
Here the
<context-root>is the name of yourwebapphelloand the
<url-pattern>is what you have specified in web.xml for that servlet.If you want to access it as http://192.168.2.10:8080/hello/HelloWorldExample2 , then change the
<url-pattern>for theservlet-mappingto /HelloWorldExample2Also, the
display-namein web.xml should match the webapp (hello) and not the servlet – but that wont cause the failure.