• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

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

Biggie_mac

OSNN Junior Addict
#1
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
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 posts

Latest profile posts

Hello, is there anybody in there? Just nod if you can hear me ...
Xie
What a long strange trip it's been. =)

Forum statistics

Threads
61,961
Messages
673,239
Members
89,014
Latest member
sanoravies