File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes 404  Error...need help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "404  Error...need help" Watch "404  Error...need help" New topic
Author

404 Error...need help

Ramesh Babu
Greenhorn

Joined: Apr 08, 2003
Posts: 16
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.


SCJP 1.4
Nart
Ranch Hand

Joined: May 28, 2002
Posts: 95
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

Joined: Apr 08, 2003
Posts: 16
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

Joined: May 28, 2002
Posts: 95
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

Joined: Apr 08, 2003
Posts: 16
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 404 Error...need help