0

I extracted tomcat-6.0.36 zip file to c:\tomcat, now root of my Tomcat installation is C:\tomcat. I have set the CLASSPATH to

".;C:\tomcat\lib\servlet-api.jar;C:\Program Files\Java\jdk1.7.0_10"

Tomcat-6.0.36 is now running and the Home page is displayed

I created the below Servlet

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HelloWorld extends HttpServlet {
   public void doGet(HttpServletRequest req, HttpServletResponse res)
                                    throws ServletException, IOException  {

                    res.setContentType("text/html");
                    PrintWriter out = res.getWriter();


                    out.println("<HTML>");
                    out.println("<HEAD><TITLE>Hello World</TITLE></HEAD>");
                    out.println("BODY");
                    out.println("<BIG>Hello World</BIG>");
                    out.println("</BODY></HTML>");


            }
}

The above Servlet was successfully compiled and the resulting .class file was placed in the directory /webapps/ROOT/WEB-INF/classes. The classes directory was not created when the Tomcat zip file was extraxted so I created it my self. Inside WEB-INF/ directory there is a web.xml file and I didn't do anything with it.

When I tried to access the Servlet HelloWorld through the URL /servlet/HelloWorld the response is

HTTP Status 404 - /servlet/HelloWorld

type Status report

message /servlet/HelloWorld

description The requested resource is not available. Apache Tomcat/6.0.36

Trying with the URL /servlets/servlet/HelloWorld resulted in the same response as above

What must be done to get the Servlets deployed? Please tell me how to modify web.xml file in the WEB-INF directory.I have referred many questions posted even on Stackoverflow, but found no solution.

Thanks

informatik01
  • 16,038
  • 10
  • 74
  • 104
Varuna
  • 1,343
  • 3
  • 15
  • 30
  • btw Why are you deploying your app to the ROOT folder? – informatik01 Jan 27 '13 at 22:31
  • @informatik01 So there isn't a separate context? – Dave Newton Jan 27 '13 at 22:31
  • 1
    Stackoverflow is not a Tutorial website. Google will give a lot of simple examples of using Servlets. For instance here is very informative and detailed tutorial: [First "Hello-world" Servlet](http://www3.ntu.edu.sg/home/ehchua/programming/java/JavaServlets.html#zz-3.). P.S. Don't give up )) – informatik01 Jan 27 '13 at 22:32
  • 1
    @Varuna Consider following essentially any Java servlet tutorial; the web.xml should have an entry for your servlet's class, and a mapping to its corresponding URL. – Dave Newton Jan 27 '13 at 22:32
  • @DaveNewton I know, but considering how he is asking, I am making a conclusion that he is knew to serlvets and maybe that was not exactly what he wanted. Maybe I'm wrong, sorry – informatik01 Jan 27 '13 at 22:35
  • 1
    Put your mouse on top of `[servlets]` tag which you placed on the question until a black box shows up and then click therein the *info* link. You'll notice that you need at least a package and a servlet mapping. You was not clear on why you were fiddling with specifically `/servlet` in URL, but perhaps you're reading an extremely old resource wherein the so-called invoker servlet is been used. You should not use that and ensure that you're reading up to date resources. See also e.g. http://stackoverflow.com/q/5031018/ – BalusC Jan 28 '13 at 00:37
  • 1
    @informatik01 Thanks for the tutorial, I am not new to tomcat or servlet programming But came after sometime, It was version 5 I was using then. – Varuna Jan 28 '13 at 02:31
  • @DaveNewton You are right, that's what exactly I was looking for, I was not aware how to configure web.xml file – Varuna Jan 28 '13 at 02:34
  • @BalusC Yes that seems to be the problem I was following the on-line tutorial at http://pdf.coreservlets.com/, But in the server setup and configuration section there is a link to an updated version of the on-line book but it also talks about the invoker servlet.The updated setup information is here http://www.coreservlets.com/Apache-Tomcat-Tutorial/ , under manual tomcat execution details the link customize the tomcat configuration carries you to Apache Tomcat 6 Tutorial where the number 5 section talks about enabling the invoker servlet, Buteven there up to now have not found on set web.xml – Varuna Jan 28 '13 at 02:49
  • @Varuna OK, I see. Anyways good luck to you! – informatik01 Jan 28 '13 at 14:50

0 Answers0