Successfully configuring servlet experience in tomcat5.0

xiaoxiao2021-03-06  46

1. First add a servlet environment variable, I use Win2000, so as long as you are 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 and Tomcat4 Different from Tomvat4 JAR files are servlet.jar to restart the computer after editing the environment variable 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 ( "

This is a servlet test "); Out.Flush ();}} You can put it in any CLASSES directory, here I choose a virtual directory D: /jsp/webappserver.xml setting: test < Serv Let-Class> Test test / test Where, Test Description Class files are Test / Test Description Laid-Declared servlet "mapping" to address / TEST, 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!!

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

New Post(0)