Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

HTTP status error 404  RSS feed

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am new to servlets. I am using Tomcat version 5.5. I am trying to run a simple servlet. The class file is under \tomcat\tcat-5.5\webapps\ch1\WEB-INF\classes. I have placed the deployment descriptor file under tomcat\tcat-5.5\webapps\ch1\WEB-INF\. I restarted Tomcat after copying the two files.

When running the command http:localhost:8080/ch1/myserv1, I get the following error.
<HR>
HTTP Status 404 - /ch1/myserv1
type Status report
message /ch1/
description The requested resource (/ch1/myserv1) is not available.
</HR>

I trust the problem is with relating the directory ch1 with Tomcat. Please advise what needs to be done.

Sen.
 
Sen George
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please ignore the tags <HR> and </HR> in the error message. Apologize for that.

Sen.
 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you please post your web.xml file?
 
Sen George
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the web.xml file.

<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
web-app_2_4.xsd"
version="2.4">
<servlet>
<servlet-name>Chapter1 Servlet</servlet-name>
<servlet-class>Ch1Servlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Chapter1 Servlet</servlet-name>
<url-pattern>myserv1</url-pattern>
</servlet-mapping>
</web-app>
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi San ,

in the xml file in the url-pattern

try this

<url-pattern>/myserv1</url-pattern>

when you use forward slash it will be relative to the context root ( in this case ch1)

besides in url type :

http://localhost:8080/ch1/myserv1

Rajesh

SCJP1.4
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Generally speaking you will save yourself a LOT of trouble if you put ALL classes involved with servlets in packages. The directory structure under WEB-INF/classes will have to reflect the package structure.
Bill
 
Sen George
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All,

It worked. The issue was with the missing forward slash in the URL pattern tag. I hope it is OK to raise a related question here.

What setting makes Tomcat to look for an application root (ch1 in my example) under webapps directory and not under bin or temp directory for example?

Thanks once again for the help.

Regards,
Sen.
 
If I had asked people what they wanted, they would have said faster horses - Ford. Tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!