Tomcat5 configuration servlet
1. Install the JDK.
2. Download Tomcat5.0.27: http://www.apache.org/dist/jakarta/tomcat-5/v5.0.27/bin/ Installed Tomcat5.0.27, I installed the path here as follows: C: / Program Files / Apache Software Foundation / Tomcat 5.0 The C: / Program Files / Apache Software Foundation / Tomcat 5.0 appears in the following, you have to replace it with your actual installation path. After installing Tomcat5.0, the test is successfully installed: execute bin / startup.bat (windows), or bin / startup.sh (linux) to start Tomcat and enter the address in the browser: http: // localhost: 80 / index .jsp (where the port is specified during the installation process. If there is a kitten appears, the installation is successful. 3. Ok, below is configured as a serrvlet. Write a simple servlet, the content is as follows:
Package test;
import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io. *;
public class Servlet extends HttpServlet {public void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {PrintWriter out = response.getWriter (); out.println ( "This is my First Servlet!");}}
Save as e: /projects/wap/servlet.java Note: Here E: / Projects / WAP is the project's directory
Compile: Javac servlet.java compiles successfully, put servlet.class in: E: /Projects/wap/web-inf/classes/test/servlet.class pay attention to the size of the size, the web-infers must be uppercase. The TEST is the name.
4. Configure the service path: to C: / Program Files / Apache Software Foundation / Tomcat 5.0 / Conf / Catalina / Localhost: New a file: wap.xml, enter the following:
5. Configure Web.xml: Find this C: / Program Files / Apache Software Foundation / Tomcat 5.0 / Conf / Web.xml Find this section:
XML Version = "1.0" Encoding = "UTF-8"?>
Of course, you can also make a manual mapping for any servlet, as follows: