1. Add a servlet's environment variable, I use Win2000, so as long as I am in my computer -> Properties -> Advanced -> Environment Variable, then create a ClassPath,
Because my Tomcat5.0 directory is in C: / Tomcat 5.0
So the variable value is c: / tomcat 5.0 / common / lib / servlet-api.jar
Different from Tomcat4 is Tomvat4's JAR file is servlet.jar
Restart your computer after editing environment variables
2. Write a servlet file
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 test extends httpservlet {
Protected Void Doget (HttpservletRequest Request, HttpservletResponse Response)
Throws servletexception, ioException {
PrintWriter out = response.getwriter ();
Out.println ("
Out.flush ();
}
}
You can put it in any CLASSES directory, here, I choose the virtual directory D: / JSP / WebApp
Server.xml settings:
Path is a virtual directory, DOCBASE is a virtual directory path There are many online settings of the virtual directory, and this is no longer introduced. Compile the generation TEST.CLASS file in D: / Classes / under D: / Classes / Under 3. That is the most critical Web.xml editing is as follows Edit the following code in servlet> servlet-maping> Among them, 4. Run: Start Tomcat, start the browser, enter http: // localhost: 8080 / WebApp / test If you see the output this is a servlet test. The written servlet is successful. If you want to run on another directory, then the principle is the same!!