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.