1

Ok, This should be basic, and I have used servlets many times before via eclipse and weblogic and no problems. However with Tomcat 6 I am having issue with Servlet mapping.

web.xml:

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
   version="2.5"> 

    <description>
      Servlet and JSP Examples.
    </description>
    <display-name>Servlet and JSP Examples</display-name>
    <servlet>
        <servlet-name>HelloWorldExample</servlet-name>
        <servlet-class>HelloWorldExample</servlet-class>
    </servlet>


    <servlet-mapping>
        <servlet-name>HelloWorldExample</servlet-name>
        <url-pattern>/HelloWorldExample</url-pattern>
    </servlet-mapping>

</web-app>

My web.xml is located in my WEB-INF folder, my servlet HelloWorldExample.class is located in WEB-INF/classes/

They are all located in tomcat/webapps/ch1/

As far as I can see it is all ok, however after hours of trial and error and multiple restarts i am still getting:

type Status report

message /ch1/HelloWorldExample

description The requested resource is not available.

http://localhost:8080/ch1/HelloWorldExample

screen shot of directory structure

folders

If someone could point out where I am making an error I would be eternally grateful :)

Rhys
  • 2,807
  • 8
  • 46
  • 68

4 Answers4

2

You should put folder "ch1" under tomcat/webapps, not under tomcat/webapps/ROOT.

Follow this folder structure:

tomcat:
--webapps
----ch1
--------META-INF
--------WEB-INF
----------classes
----------lib
----------web.xml
Jason
  • 1,241
  • 8
  • 16
2

You should build and export a WAR file and deploy it on Tomcat, then it will automatically go on the right place. Also, pay attention on this part of your web.xml:

<servlet>
    <servlet-name>HelloWorldExample</servlet-name>
    <servlet-class>HelloWorldExample</servlet-class>
</servlet>

Servlet-class needs to be fully qualified class name, that is: your.package.classname (ignore if you are using default package, which is a bad practice generally). When you deal with this problem, I would suggest that you install Tomcat 7 and take advantage of Servlet 3.0 benefits, i.e. get rid of web.xml configuration and use servlet annotations. More info:

Community
  • 1
  • 1
Miljen Mikic
  • 14,765
  • 8
  • 58
  • 66
  • I agree packaging is best, but this is test and should work like this. Also annotaion and 3.0 is great,however the system I have use is 2.5 only. Hence the web.xml – Rhys Feb 20 '13 at 08:02
  • @Rhys I understand. However, as I suggested, package your project into war and deploy it - it should resolve your problem. – Miljen Mikic Feb 20 '13 at 08:08
  • I just deployed to war, Added to webapps root and restarted and no luck there either. I think my tomcat installation is faulty – Rhys Feb 20 '13 at 08:15
  • @Rhys How did you deploy it? Using Tomcat Web console (usually, http://localhost:8080/manager) or manually copying/extracting? I would strongly suggest first approach. – Miljen Mikic Feb 20 '13 at 08:23
  • 1
    it ended up being the fact that I compiled it with 1.6 and java_home is version 1.7. All working now. CHeers. – Rhys Feb 21 '13 at 04:50
0

Your ch1 folder should be under webapps not under webapps/ROOT

0

please move the ch1 folder to webapps from webapps/ROOT And remember to restart the Tomcat Server after this change

Sudhakar
  • 4,823
  • 2
  • 35
  • 42