Tomcat5 configuration servlet

xiaoxiao2021-03-06  78

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: explanation: path: This is the access path, indicating that you want to join in the browser address bar. DOCBASE: The project file path, here is what the e: / projects / wapreloadable: set to TRUE, modify the servlet file, the JSP file, can take effect without restart Tomcat.

5. Configure Web.xml: Find this C: / Program Files / Apache Software Foundation / Tomcat 5.0 / Conf / Web.xml Find this section: invoker < Servlet-Class> Org.apache.catalina.Servlets.invokerServlet debug 0 2 -> This is commented. Remove the comment. This step is the most important. Go to your project directory: E: / Projects / WAP / Web-INF here New Web.xml: The input content is as follows:

WAP invoker / servlet / * The meaning of this paragraph is to say that there is no specially specified servlet, use / servlet / * to map it.

Of course, you can also make a manual mapping for any servlet, as follows: servlet test / servlet servlet / servlet / servlet Save.

转载请注明原文地址:https://www.9cbs.com/read-120812.html

New Post(0)