My First Servlet

I downloaded the "tomcat" software and installed it. I then added the following "environment variables" in Win XP.
CATALINA_HOME
D:\Program Files\Java\jakarta-tomcat-4.0.6
CLASSPATH
D:\Program Files\Java\jakarta-tomcat-4.0.6\common\lib\servlet.jar
JAVA_HOME
D:\Program Files\Java\j2sdk1.4.0_02
TOMCAT_HOME
D:\Program Files\Java\jakarta-tomcat-4.0.6
Path
D:\Program Files\Java\JBuilder\jdk1.3.1\bin;%JAVA_HOME%\bin
Before I added the ClassPath, I tested Tomcat with the supplied samples and they all come up just fine (or course I ran the start.bat to invoke Tomcat).
I then attempted to compile a simple little program and this is where I found that I had omitted including the "classpath".
The compile now works fine, but now nothing works on Tomcat, including the "samples" which previously worked just fine. What am I doing wrong?
Any ideas?
When the Tomcat is started, I get the following messages (which are the normal messages....right?)
Starting service Tomcat-Standalone
Apache Tomcat/4.0.6
Starting service Tomcat-Apache
Apache Tomcat/4.0.6
When I stop it, I get a window that comes up for a second and displays the following...
Using CATALINA_BASE D:\Program Files\Java\jakarta-tomcat-4.0.6
Using CATALINA_HOME D:\Program Files\Java\jakarta-tomcat-4.0.6
Using CATALINA_TMPDIR D:\Program Files\Java\jakarta-tomcat-4.0.6
Using JAVA_HOME D:\Program Files\Java\j2sdk1.4.0_02
I did install and uninstall a "newer release" because the "shutdown.bat" would not shut down Tomcat.
Any Ideas as to what I should look at??????????
Thanks in advance!!!

No I have not modified the tomcat conf files.
I did not create an XML from my servlet.
I placed my servlet in the following directory:
D:\Program Files\Java\jakarta-tomcat-4.0.6\webapps\ROOT\WEB-INF\classes
I rebooted my machine and now "my application" now shows up in the browser. When I make any change to my application it will not show up in the browser until I take Tomcat down and bring it back up again. I don't think this is right....is it?
To bring up my application I put the following in the browser:
http://localhost:8080/servlet/MyHello
I do not have a clue as to what "was" the problem, I am still very suspicious that something is still not correct.

Similar Messages

  • Help required in First Servlet

    Hey Guys.....I have read the above thread all posts and as this is also my first Servlet so I am also getting
    java.lang.ClassNotFoundException: servlets.HelloWorldServlet
    Now in my Apache tomcat folder C:\apache-tomcat-6.0.16\webapps\ServletExamples I have the WEB-INF folder.....which has the web.xml....
    Web.xml is something like this...
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5">
         <servlet>
              <servlet-name>HelloWorldServlet</servlet-name>
              <servlet-class>servlets.HelloWorldServlet</servlet-class>
         </servlet>
         <servlet>
              <servlet-name>LoginServlet</servlet-name>
              <servlet-class>servlets.LoginServlet</servlet-class>
         </servlet>
         <servlet-mapping>
              <servlet-name>HelloWorldServlet</servlet-name>
              <url-pattern>/HelloWorldServlet</url-pattern>
         </servlet-mapping>
         <servlet-mapping>
              <servlet-name>LoginServlet</servlet-name>
              <url-pattern>/LoginServlet</url-pattern>
         </servlet-mapping>
    </web-app>The HelloWorldServlet.java is
    package servlets;
    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 request, HttpServletResponse response) throws ServletException, IOException{
              PrintWriter pw = response.getWriter();
              pw.println("<html>");
              pw.println("<head>");
              pw.println("</head>");
              pw.println("<body>");
              pw.println("<h3>Hello World as a Servlet</h3>");
              pw.println("</body>");
              pw.println("</html>");
    }and this is what I am writing on the url......
    http://localhost:8080/ServletExamples/HelloWorldServlet
    and I am assuming that the problem is coming in the <servlet-class> in the fully qualified name....
    So I decided to make a classes folder in the WEB-INF folder and copy all my .class files and .java files in it.....
    after this I am still getting the same error....
    java.lang.ClassNotFoundException: servlets.HelloWorldServlet
    and when I refresh it again it gives me a different error....which is
    type Status report
    message Servlet HelloWorldServlet is not available
    description The requested resource (Servlet HelloWorldServlet is not available) is not available.
    So how can anybody help me out in starting my carrier in the servlets...
    Thanks in advance
    Regards
    ISI

    Please can anyone suggest any good tutorials which can help me in this.....I am following this one but I am unable to overcome this error...
    http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Servlets.html
    Regards
    ISI

  • Problem with first servlet

    Hi
    I am trying to run my first servlet HelloWorld
    I have my servlet in the directory
    Tomcat 4.1/webapps/test/web-inf/classes/HelloWorld.class
    and my web.xml file in the directory
    Tomcat 4.1/webapps/test/web-inf/web.xml
    contains the following lines
    <web-app>
    <servlet>
    <servlet-name>HelloWorld</servlet-name>
    <servlet-class>HelloWorld</servlet-class>
    </servlet>
    <servlet-mapping>
         <servlet-name>HelloWorld</servlet-name>
    <url-pattern>/HelloWorld</url-pattern>
    </web-app>
    I also have changed the conf/server.xml file for the context as follows
         <Context path="/test" docBase="test" debug="0"
    reloadable="true" crossContext="true">
    and now when I try http://localhost:8080/test/servlet/HelloWorld
    Still I am getting the error status 404 The requested resource /test/servlet/HelloWorld not found.
    What am I doing wrong ????
    When I put my HelloWorld.class file in the webapps/examples directory it runs fine.WHy is it so ?
    Also for the above I have not started my tomcat server since I tried to run my HelloWorld from examples using http://localhost:8080/examples/servlet/HelloWorld it works perfect so I think I do not need to start server.
    Please reply me

    Try fully qualifying your servlet-class so that it reads something like this: <servlet-class>examples.servlet.HelloWorld</servlet-class>

  • My First servlet error-HTTP Status 500

    Recently Installed apache-tomcat-5.5.27 ,I followed one documentation when i googled for a while like is here [http://linux-sxs.org/internet_serving/c292.html]
    when i try to access from web-browser ,it came up with errors like
    HTTP Status 500 -
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception
    javax.servlet.ServletException: Error allocating a servlet instance
         org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
         org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
         org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)
         org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
         org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
         org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
         org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
         java.lang.Thread.run(Thread.java:595)
    root cause
    java.lang.UnsupportedClassVersionError: Bad version number in .class file
         java.lang.ClassLoader.defineClass1(Native Method)
         java.lang.ClassLoader.defineClass(ClassLoader.java:620)
         java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
         org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1876)
         org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:889)
         org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1353)
         org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1232)
         org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
         org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
         org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)
         org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
         org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
         org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
         org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
         java.lang.Thread.run(Thread.java:595)
    note The full stack trace of the root cause is available in the Apache Tomcat/5.5.27 logs.Here is the directory structure
    #/opt/apache-tomcat-5.5.27/webapps/MyFirst
    #/opt/apache-tomcat-5.5.27/webapps/MyFirst/WEB-INF
    #/opt/apache-tomcat-5.5.27/webapps/MyFirst/WEB-INF/classes
    #/opt/apache-tomcat-5.5.27/webapps/MyFirst/WEB-INF/libI placed web.xml file in WEB-INF directory and HelloWorld.class in WEB-INF/classes and MyFirst.xml in /opt/apache-tomcat-5.5.27/conf/Catalina/localhost/
    the files typically contains
    web.xml
    <?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>HelloWorld</servlet-name>
            <servlet-class>HelloWorld</servlet-class>
    </servlet>
    <servlet-mapping>
            <servlet-name>HelloWorld</servlet-name>
            <url-pattern>/HelloWorld</url-pattern>
    </servlet-mapping>
    </web-app>
    HelloWorld.java
    // Filename : HelloWorld.java                                                                                                                               
    // Description : This servlet merely says hello!                                                                                                            
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class HelloWorld extends HttpServlet {
        public void doGet ( HttpServletRequest request, HttpServletResponse response )
            throws ServletException, IOException    {
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            out.println("<html>");
            out.println("<head><title>Hello, Cruel World!</title></head>");
            out.println("<body>");
            out.println("<h1>Hello, Cruel World !</h1>");
            out.println("This is my first servlet.");
            out.println("</body>");
        }// end doGet                                                                                                                                           
    }///:~
    MyFirst.xml
    <!-- MyFirst Context -->
    <Context path="/MyFirst" docBase="MyFirst" debug="0" reloadable="true"/>anybody have idea about this error...

    miriyalasrinivas wrote:
    java.lang.UnsupportedClassVersionError: Bad version number in .class fileThe class is compiled with a JDK version which is newer than the JRE version used to run the class. To solve this, just clean up your Java environment and align the versions. You can get version information of the Java compiler using javac -version and of the Java runtime using java -version.
    That said, this problem is actually not related to servlets. You didn't get a root exception of javax.servlet package. You just got a root exception of java.lang package, which basically makes it a Java SE problem. Questions related to those actually belongs in the 'New to Java' forum.

  • Running my first Servlet on TOMCAT - 10 duke dollars

    I am very new to Servlets. I am not creating a seperate context on Tomcat root to load the Servlet.
    I did the automatic installation of Tomcat 4.0.3 on windows NT available on <jakarta.apache.org/tomcat>
    I am going to load my servlet class in c:\<Tomcat Home>\Web Apps\Root\Web-inf\Classes
    But under my <Root\Web-inf> there is NO <Classes> subdirectory. So I created one and copied my class file there.
    Then on the browser, I typed
    http://127.0.0.1:8080/servlet/myFirstServlet
    Then I am getting the 404 Http Not found error.
    Error in detail is "/servlet/myFirstServlet" not found
    Can someone PLEASE help me ASAP.

    NOTE: I already sent this message under different heading.. I am sending this message under this for Mr/Mrs w234 ....
    Please let me know....
    I wrote my first Servlet with Forms, for a registration system. I have my input HTML file first.html and my java class (first.java) which processes the form and spits out the same information thru' the servlet.
    I added the line below in my server.xml in /conf directory, Forms is the subdirectory under webapps
    <Context path="/Forms" docBase="Forms" debug="0"
    reloadable="true" crossContext="true" />
    I created the web.xml as follows in c:<Tomcat home>\webapps\Forms\web-inf\web.xml
    <?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>first</servlet-name>
    <servlet-class>first</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>first</servlet-name>
    <url-pattern>/first</url-pattern>
    </servlet-mapping>
    </web-app>
    Note : My HTML file name and class files name both are same.. Also can someone tell me how to change web.xml for different HTML file name and class name ? Or do we have to include HTML file here in web.xml ?
    I am confused !!
    Then in the browser I typed
    http://127.0.0.1:8080/Forms/servlet/first.html
    I am getting this error
    Apache Tomcat/4.0.3 - HTTP Status 404 - /first.html
    type Status report
    message /first.html
    description The requested resource (/first.html) is not available.
    Can you please HELP ...
    Still I have not figure out how to give a couple of Duke s ? Please help me ...

  • Can't compile my first servlet program

    hi guys,
    there are some problems with compiling the first servlet program(helloservlet).
    the error is following
    C:\SERVLET-CODE\hello1>javac HelloServlet.java
    HelloServlet.java:4: package javax.servlet does not exist
    import javax.servlet.*;
    ^
    HelloServlet.java:5: package javax.servlet.http does not exist
    import javax.servlet.http.*;
    ^
    HelloServlet.java:15: cannot resolve symbol
    symbol : class HttpServlet
    location: class HelloServlet
    public class HelloServlet extends HttpServlet {
    ^
    HelloServlet.java:16: cannot resolve symbol
    symbol : class HttpServletRequest
    location: class HelloServlet
    public void doGet(HttpServletRequest request,
    ^
    HelloServlet.java:17: cannot resolve symbol
    symbol : class HttpServletResponse
    location: class HelloServlet
    HttpServletResponse response)
    ^
    HelloServlet.java:18: cannot resolve symbol
    symbol : class ServletException
    location: class HelloServlet
    throws ServletException, IOException {
    ^
    6 errors
    i don't know why it can not find the import java.*
    and i already set up the classpath
    and my code is
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    /** Simple servlet used to test server.
    * <P>
    * Taken from More Servlets and JavaServer Pages
    * from Prentice Hall and Sun Microsystems Press,
    * http://www.moreservlets.com/.
    * &copy; 2002 Marty Hall; may be freely used or adapted.
    public class HelloServlet extends HttpServlet {
    public void doGet(HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException, IOException {
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    String docType =
    "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
    "Transitional//EN\">\n";
    out.println(docType +
    "<HTML>\n" +
    "<HEAD><TITLE>Hello</TITLE></HEAD>\n" +
    "<BODY BGCOLOR=\"#FDF5E6\">\n" +
    "<H1>Hello</H1>\n" +
    "</BODY></HTML>");
    please help me out of it...
    thank you all...

    hi man,
    thanks for the classpath, and i already did it in system environment.
    but it can not work either...
    do i really have to download the API, so where i have to put it after i download it...

  • Fail to run my first Servlet with Sun ONE Studio 4 Update 1 (+ bi Tomcat)

    Hello !
    I failed to run my first Servlet with Sun ONE Studio 4 update 1 ( with built in Tomcat)
    I think that I followed most of the online instructions,
    so I successfully run a JSP file,
    but I failed with my first servlet:
    The error message is:
    "Standard Wrapper[:MyServlet]: Marking servlet MyServlet as unavailable
    javax.servlet.ServletException: Wrapper cannot find servlet class com.hemmerling.myservlet.MyServlet
    or a class it depends on
    So please don�t ask me for the code of the servlett ( simply taken from a book),
    but tell me why the one-and-only servlett was not found. what might I have done wrong, if I did everything I did to run the JSP file, too ?
    Of couse I copied the file into the "Classes" directory of the Webmodule ( WEB-INF ) and "processed" it, so that I was able to execute it.
    Any suggestions ?
    Tia
    Sincerely
    Rolf

    Tough to say, but try:
    1. Put the servlet in a package. If you're using the default package (class file in WEB-INF/classes directory, then Tomcat may not find it.
    2. Check out web.xml to ensure the <servlet> and <servlet-mapping> entries are correct.
    3. Make the servlet as simple as possible so you're sure that it is the servlet itself that cannot be found and not some other class that it uses.
    Good Luck

  • Trying to run my first servlet through Eclipse + XAMPP

    I'm trying to run my first servlet through eclipse, I'm using XAMPP + Tomcat add-on as my webserver. How do I even try and compile my servlet? I've added the external jar Servlet-api.jar to my project as stated in here, http://www.theserverside.com/discussions/thread.tss?thread_id=37924
    But eclipse wouldn't compile it, because there just isn't a main() in my servlet program..
    Do I need to install the WPT plugin for eclipse? I'm guessing I'm not setting my CLASSPATH correctly - Do I need to set it up manually?

    Nevermind, there were lots of Issues going the XAMPP way, so I just installed Tomcat separately and all is fine now.
    I used instructions from http://www.scribd.com/doc/495993/Installing-Apache-Tomcat-6-and-Using-It-With-Eclipse and it was a walk-in-the-park..

  • Need help getting first servlet to run in tomcat

    hi,
    i've complied my first servlet ok, using tomcat as server, problem is it can't find it. i up the class file under Web-inf/myApp under tomcat directory, typed:
    http://localhost:8080/myApp/TestingServlet
    in the url but it can't locate it. also i did start tomcat before going to url. can someone tell me what am i missing?
    Thank you.

    ok i got it to run but i had to create a classes dir under web-inf and had to use the url:
    http://localhost:8080/myApp/servlet/TestingServlet
    but why the servlet in the url, i don't have a servlet dir, does tomcat map classes dir to servlet dir?
    Thank you.

  • Not able to run my first Servlet..... 404 error!!!

    Hi,
    I am new to Java.
    I am trying to create a small servlet application. I am using Tomcat 5.5 server and eclipse for this.
    I have first writtern a HTML form which on submission is redirected to a servlet that displays the information submitted. but i am not able to evn open the html file through browser, i am getting 404 error.
    My html codes and Servlet codes are inside the htmlform package...
    When i type http://localhost:8080/htmlform/form.html i am gettig 404 error... Also let me know if any thing is wrong with the codes...
    Here is my code...
    form.html
    <html>
    <head>
    <title> This is a HTML page </title>
    </head>
    <body>
    <p><h3>This page displays a submission form</h3></p>
    <form method="GET" action="/htmlform/LoginServlet">
    <p> USERNAME: <input type="text" name="username"/> </p>
    <p> PASSWORD: <input type="password" name="password" /> </p>
    <p> <input type="submit" value="Press Me" name="submit"/> </p>
    </form>
    </body>
    </html>
    LoginServlet.java
    package htmlform;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class LoginServlet extends HttpServlet{
         private static final long serialVersionUID = 1L;
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    response.setContentType("text/html");
    PrintWriter pw = response.getWriter();
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    pw.println("<html><head><title>This is the out put page</title></head");
    pw.println("<body><h2>If you can see this page then your form is cleanly processed</h2><br>");
    pw.println("<h2>Congratulations!!!</h2>");
    pw.println("<p>Your user name is: "+ username+ "</p>");
    pw.println("<p>Your password is: "+ password + "</p>");
    pw.println("<br></body></html>");
    web.xml
    <?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>Login</servlet-name>
    <servlet-class>LoginServlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>Login</servlet-name>
    <url-pattern>/login</url-pattern>
    </servlet-mapping>
    </web-app>
    Thanks in advance

    you might have other problems, but I think the action attribute in your HTML form is incorrect.
    You have:
    <form method="GET" action="/htmlform/LoginServlet">Your web.xml says:
    <servlet-mapping>
    <servlet-name>Login</servlet-name>
    <url-pattern>/login</url-pattern>
    </servlet-mapping>So I think you should change the action like this:
    <form method="GET" action="/htmlform/login">Your servlet's not in a package, and you might not be deploying it correctly (god forbid you added this to /ROOT), but try that first.
    %

  • First servlet attempt in J2EE

    Hi
    A very very simple question for you. I'm using the deployment tool, I've created a new application, created a new WAR and added my servlet. I'm trying to get it working locally (Win98), and the server is running.
    When I click deploy, the first thing it wants is an existing Deployment Settings File Name, which it proposes as D:\progs\j2sdkee1.4\public_html\test5\test5.ear.xml
    But test5.ear.xml doesn't exist. So what should I do? Have I missed a step? I'm getting all kinds of deployment errors as a result.
    Another thread suggested (to another enquirer) they should choose File, Deployment Settings, Create New File, but whenever I try that I get Suns J2EE Reference Implementation in the left hand tree display, but my ear and war are greyed and I can't deploy any more.
    Cheers
    J

    I got it fixed. I ended up getting lots of Corba errors, and I closed the whole thing down, brought it up again, and it worked. Halleluyah :-)
    J

  • Cant see my First Servlet

    HI
    I am using tomcat 5.0.25. and my application server is running well with all my jsp pages. I have to use servlet very soon. So I am playing with simple Hello servlet. But after following all the steps(?), I am not able to view my servlet , instead I get 404 error. Obviously I am missing something. Here is how I do it:
    I created a folder 'ts' inside $CATALINA-HOME/webapps/ROOT.
    I created a folder WEB_INF inside ts.
    Inside WEB_INF, I created 'web.xml' and 2 folders :'classes' &  'lib'
    My 'lib' folder is now empty. I compile my HelloServlet class and place HelloServlet.class inside the folder 'classes'here is the content of web.xml file:
    <?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>
      <display-name>My First Servelt</display-name>
      <description>
         First Test servlet
      </description>
    <!-- JSPC servlet mappings start -->
        <servlet>
            <servlet-name>HelloServlet</servlet-name>
            <servlet-class>HelloServlet</servlet-class>
        </servlet>
        <servlet-mapping>
            <servlet-name>HelloServlet</servlet-name>
            <url-pattern>/HelloServlet</url-pattern>
        </servlet-mapping>
    <!-- JSPC servlet mappings end -->
    </web-app>Here is how I invoke my HelloServlet:
    http://127.0.0.1:8080/testservlet/HelloServlet
    But unable to see my servlet. Somewhere , I heard something about 'adding context to server.xml' . But dont know why and how. Does my problem has to do with this? Any help will be appreciated.
    TIA
    tiptip

    Well here I am with my result: Try to follow the exact procedure again and again but unsuccess ul. There is a folder called servlets-examples that comes with tomcat and I can successfully invoke those servlet from browser.
    Here what I did so far:
    I created a folder 'example' inside $CATALINA_HOME/webapps
    Inside that  I created  a web.xml file and two folders: classes & lib
    Inside classes I created a folder called 'pack1'
    Inside pack1, I place my HelloWorldExample.classHere is my HelloWorldExample.java
    package pack1;
    import java.io.*;
    import java.text.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    * The simplest possible servlet.
    * @author James Duncan Davidson
    public class HelloWorldExample extends HttpServlet {
      public void doGet(HttpServletRequest request,HttpServletResponse response)
                          throws IOException, ServletException    {
           String title = "HELLO WORLD";
            response.setContentType("text/html");
            PrintWriter out = response.getWriter();
            out.println("<html>");
            out.println("<head>");       
            out.println("<title>" + title + "</title>");
            out.println("</head>");
            out.println("<body bgcolor=\"white\">");
            out.println("<h1>" + title + "</h1>");
            out.println("</body>");
            out.println("</html>");
    }here is web.xml file:
    <?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>
        <display-name>Servlet 2.4 Examples</display-name>
        <description>
          Servlet 2.4 Examples.
        </description>
        <!-- Define servlets that are included in the example application -->
        <servlet>
            <servlet-name>HelloWorldExample</servlet-name>
            <servlet-class>pack1.HelloWorldExample</servlet-class>
        </servlet>
        <servlet-mapping>
            <servlet-name>HelloWorldExample</servlet-name>
            <url-pattern>/HelloWorldExample</url-pattern>
        </servlet-mapping>
       </web-app>Here is how I invoke my servlet:
    http://127.0.0.1:8080/example/HelloWorldExample
    Yet no clue about how I can see my own servlet. Thanks

  • First Servlet Program: Whats the error now?

    I have changed my web.xml file. Its small now:
    <?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/j2ee/dtds/web-app_2_3.dtd">
    <web-app>
    <servlet>
    <servlet-name>Brat</servlet-name>
    <servlet-class>Brat</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>Brat</servlet-name>
    <url-pattern>/Brat</url-pattern>
    </servlet-mapping>
    </web-app>
    My URL is:
    http://localhost:8080/examples/Brat
    & I have copied Brat.class in the webapps,
    webapps/examples, webapps/examples/servlets direcories but still its complaining about its location. I am getting following errors at different imes:
    HTTP Status 503 - Servlet Brat is currently unavailable
    The requested service (Servlet Brat is currently unavailable) is not currently available.
    A Servlet Exception Has Occurred
    Exception Report:
    javax.servlet.ServletException: Wrapper cannot find servlet class Brat or a class it depends on
         at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:797)
         at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:602)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:231)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:225)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2252)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:446)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:163)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:875)
         at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:952)
         at java.lang.Thread.run(Thread.java:484)
    Root Cause:
    java.lang.ClassNotFoundException: Brat
         at org.apache.catalina.loader.StandardClassLoader.loadClass(StandardClassLoader.java:1111)
         at org.apache.catalina.loader.StandardClassLoader.loadClass(StandardClassLoader.java:976)
         at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:792)
         at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:602)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:231)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:225)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2252)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:164)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:446)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:163)
         at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
         at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:875)
         at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:952)
         at java.lang.Thread.run(Thread.java:484)
    Can somebody plz help me?
    Zulfi.

    C:\, C:\WINNT are directories unrelated to Tomcat that Tomcat doesn't know about (unless you told it about them in the conf/server.xml file).
    A simple solution without editing your server.xml file is to use Tomcat's ROOT directory.
    This directory is by default <Tomcat install directory>\webapps\ROOT
    (For me it's : C:\Program Files\Tomcat 4.1\webapps\ROOT).
    In this ROOT directory you have the WEB-INF directory wich contains the web.xml file.
    Under this WEB-INF directory create a directory called "classes" and put a copy of you servlet class file in it.
    The complete path of your servlet class file then should be
    <Tomcat install directory>\webapps\ROOT\WEB-INF\classes\Brat.class
    Try this and report if it worked.

  • Deploying my first servlet in tomcat

    I have HTML form using get method as below
    <HR><FORM method="GET" action="http://localhost:8080/Project/Formservlet"> and the Formservlet is in
    project/Web-INF/classes
    web.xml is in
    project/Web-INF
    set the context to Project directory in server.xml
    The content of web.xml
    <!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>Formservlet</servlet-name>
    <servlet-class>Formservlet</servlet-class>
    </servlet>
    <servlet-mapping>
    <servlet-name>Formservlet</servlet-name>
    <url-pattern>/Formservlet</url-pattern>
    </servlet-mapping>
    </web-app>but when i tried to submit the data of form it says
    "The requested resource (/Project/Formservlet) is not available"
    can anybody help me on this?

    The class has to be in a package.
    package project; //note it's a standard to have pkg names lower case.
    public class FormServlet{
    }Needless to say, when you put the class in a package project, the physical .java file has to be in a directory called 'project'.
    And after you compile it, the .class file should be placed in the classes folder with the packaging. Thus your .class file ought to be in
    <YOUR_WEB_ROOT>/WEB-INF/classes/project/FormServlet.classAnd finally your web.xml file should mention the fully qualified .class name - i.e
    <servlet-name>Formservlet</servlet-name>
    <servlet-class>project.Formservlet</servlet-class>ram.

  • Compiling my first servlet

    I tried to compile HelloWorldServlet.java(taken from sunexamples) stored in JavaWebServer2.0\servlets.
    I have JavaWebServer2.0 and have included servlet.jar in my environment variables.
    I was getting an error can't find class sun/tools/javac/main.
    Then,I took tools.jar from my jdk1.3, and pasted in JavaWebServer2.0\lib and included tools.jar in environment variables.
    Now I get errors:
    java.lang.NoClassDefFoundError:java/util/ArrayList
         at sun.tools.util.CommandLine.parse(Compiled Code)
         at sun.tools.javac.Main.compile(Compiled Code)
         at sun.tools.javac.Main.main(Main.java:729)
    PLEASE HELP ME.
    Is it wrong to copy-paste tools.jar?How can I compile?

    Here is part of a batch file I use for my command line compiling.
    SET JAVA_HOME=C:\jdk1.3.1_09
    SET CLASSPATH=.;C:\jdk1.3.1_09\lib\jt400.jar;C:\jdk1.3.1_09\lib\tools.jar;C:\jdk1.3.1_09\lib\classes12.zip;C:\jdk1.3.1_09\lib\jregex1.2_01.jar
    SET PATH=c:\jdk1.3.1_09\binCreate a file with extension .bat and add this. Make changes to your jars and directories as needed.

  • Compiling my first servlet page

    Hi,
    Im not able to compile my servlet.The servlet code is in desktop\java.The servlet.jar is in c:\program files \ apache tomcat 4.0\common\lib
    when i give this command
    javac HelloServlet.java -classpath " c:\--------" it is not working.I dont know whether this is correct.Please help me out.

    Adding the servlet.jar to tomcat won't make the java compiler know where it is unless the code is called from an application in the web container.
    use javac -cp "filename"
    Otherwise I'd suggest you'd get an IDE to which you add the jar and then compile using the IDE.
    Don't waste your time with javac!

Maybe you are looking for