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

Biggie_mac

OSNN Junior Addict
Joined
16 Feb 2005
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!!
 
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.
 

Members online

No members online now.

Latest profile posts

Also Hi EP and people. I found this place again while looking through a oooollllllldddd backup. I have filled over 10TB and was looking at my collection of antiques. Any bids on the 500Mhz Win 95 fix?
Any of the SP crew still out there?
Xie wrote on Electronic Punk's profile.
Impressed you have kept this alive this long EP! So many sites have come and gone. :(

Just did some crude math and I apparently joined almost 18yrs ago, how is that possible???
hello peeps... is been some time since i last came here.
Electronic Punk wrote on Sazar's profile.
Rest in peace my friend, been trying to find you and finally did in the worst way imaginable.

Forum statistics

Threads
62,015
Messages
673,494
Members
5,621
Latest member
naeemsafi
Back