the simplest servlet...and it doesn't work.help need!!pls

Discussion in 'Web Design & Coding' started by Biggie_mac, Mar 23, 2006.

  1. Biggie_mac

    Biggie_mac OSNN Junior Addict

    Messages:
    18
    I have a very simple servlet to run....and it doesn't work..I dwl Tomcat 5.0.28, installed it to C:\Tomcat 5....started the procces, typed localhost:8080 in the browser...everything worked out. I even tried some of thei examples and they worked. Now I want to run this very simple servlet:

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

    public class SimpleCounter extends HttpServlet {

    int count = 0;

    public void doGet(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException {
    res.setContentType("text/plain");
    PrintWriter out = res.getWriter();
    count++;
    out.println("Since loading, this servlet has been accessed " +
    count + " times.");
    }
    }


    I saved the file as SimpleCounter.java, copy it to ROOT/Web-inf/classes/ and typed localhost:8080/servlet/SimpleCounter.
    As I read on tutorials and books this is the simplest way to run a servlet. But it doesn't work for me!! I get this message:

    HTTP Status 404 - /servlet/SimpleCounter
    type Status report
    message /servlet/SimpleCounter
    description The requested resource (/servlet/SimpleCounter) is not available.
    Apache Tomcat/5.0.28


    What am I doing wrong? I'm new with servlets so ....

    10x very much!!
     
  2. Geffy

    Geffy Moderator Folding Team

    Messages:
    7,805
    Location:
    United Kingdom
    its been a while since I last did Servlets but I think you need to compile the SimpleCounter.java into SimpleCounter.class

    do this
    Code:
    javac SimpleCounter.java
    and you should end up with a compiled version. Then it should work.

    From what I remember JSP files are compiled by tomcat the first time they are run and from there they are used in the byte form. I think Servlets you have to do though.