• 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
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

404 Error...need help  RSS feed

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have just started to work with Tomcat and trying to run HelloWorldServlet from Hanumant...
I think I am doing some mistake to run HelloWorldservlet...
Here is what I did.
Written a class and compiled and put it under webapps\chapter01\WEB-INF\classes\
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class HelloWorldServlet extends HttpServlet {
public void service(HttpServletRequest req, HttpServletResponse res )
throws ServletException, IOException {
PrintWriter pw = res.getWriter();

pw.println("<html>");
pw.println("<head>");
pw.println("</head>");
pw.println("<body>");
pw.println("<h3> Hello World - From Ramesh </h3> ");
pw.println("</body>");
pw.println("<html>");
}




}
and put web.xml under webapps\chapter01\WEB-INF
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>HelloWorldServlet</servlet-name>
<servlet-class>HelloWorldServlet</servlet-class>
</servlet>
</web-app>

But here what I have doubt....it says type the following on browser
http://localhost:8080/chapter01/servlet/HelloWorldServlet
where did this servlet directory comes from .... I even tried to remove the servlet directory it still says
Apache Tomcat/4.0.1 - HTTP Status 404 - /chapter/servlet/HelloWorldServlet
description The requested resource (/chapter/servlet/HelloWorldServlet) is not available.
 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ramesh,
Your example works in a servlet container with an 'invoker servlet' enabled. Older versions of Tomcat used to enable it by default.
For an explanation of the 'invoker servlet' read this: http://test.javaranch.com/wiki/view?InvokerServlet
To make your example work, add this to your web.xml file:

Add it after the servlet element, after the closing </servlet>.
For an explanation on why this works now, check section 5.2.3 in 'SCWCD Exam Study Kit' by Hanumant Deshmukh.
Nart
[ March 18, 2004: Message edited by: Nart Seine ]
[ March 18, 2004: Message edited by: Nart Seine ]
 
Ramesh Babu
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nart,
Thanks for your quick response...Still I have one double
from where does this "/servlet/ " comes from....You can see from the code that I didn't put it in any package....
<servlet-mapping> <servlet-name>HelloWorldServlet</servlet-name> <url-pattern>/servlet/HelloWorldServlet</url-pattern></servlet-mapping>

I tried still not working ...I know I am missing very small thing...
Thanks for you time
Ramesh
 
Nart
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is how web.xml should look like:

Your deploymeny directory structure would like this:

start tomcat and access the servlet using:
http://localhost:8080/chapter01/servlet/HelloWorldServlet
And that should do it
If you still have an error, double check everything, if still in trouble get the updated book source code here: http://www.jdiscuss.com/misc/scwcdkit-examples-webapps.jar
That should solve your problems.
Good luck
 
Ramesh Babu
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nart,
My sincere thanks for you reply. It was a great help to have that jar file.. I made a lot of mistakes like...classpath, home directory...etc...
I had too many Tomcat installed...each one pointing each direction....finally I made it to run...
Thanks
Ramesh
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!