[Reproduced] Configure servlet under Tomcat

xiaoxiao2021-03-06  49

Tomcat Novice Raiders 1, download the necessary software 1jdk 1.4.2 2tomcat 4.0 2, Configuring Environment Windows System User: My Computer ------> Right -------> Properties -------> Detailed -------> Environment Variable Path = x: /jdk1.4.2/bin java_home = x: /jdk1.4.2 Catalina_Home = x: / tomcat (here is Tomcat_Home = x: / Tomcat) Note: Here X is Installed drive. Here is how to set up the Startup.bat file in the bin directory. We can open Startup.bat in the editing state, see that this file needs to read the system variable, we set the one.

For example, the current STARTUP.BAT file content of my version Tomcat is as follows: @echo off if "% os%" == "windows_nt" setLocal Rem ---------------------------------------------------------------------------------------------------------------------------- -------------------------------------------------- ---- Rem Start Script for the Catalina Server Rem Rem $ ID: Startup.bat, V 1.4 2002/01/15 02:55:38 Patrickl Exp $ REM ------------- -------------------------------------------------- ------------ Rem Guess Catalina_Home if not defined if not "% CATALINA_HOME%" == "" goto gothome set catalina_home =. if exist "% catalina_home% / bin / catalina.bat" goto okhome set CATALINA_HOME = ..: gotHome if exist "% CATALINA_HOME% / bin / catalina.bat" goto okHome echo The CATALINA_HOME environment variable is not defined correctly echo This environment variable is needed to run this program goto end: okHome set EXECUTABLE =% CATALINA_HOME % / bin / catalina.bat rem Check that target executable exists if exist "% EXECUTABLE%" goto okExec echo Can not find% EXECUTABLE% echo This file is needed to run this program goto end: okExec rem Get remaining unshifted command line argum ents and save them in the set CMD_LINE_ARGS =: setArgs if ""% 1 "" == "" "" goto doneSetArgs set CMD_LINE_ARGS =% CMD_LINE_ARGS%% 1 shift goto setArgs: doneSetArgs call "% EXECUTABLE%" start% CMD_LINE_ARGS%: End We can clearly see that this file needs to read the value of the system variable Catalina_home, so we can set the Catalina_home set to Tomcat in the environment variable. 3, start, close Tomcat has 2 methods can be started, close the installed Tomcat: 1 Direct click Run BIN directory STARTUP.BAT and shutdown.bat files. 2 Since we set the path before, we directly type Startup or shutdown directly in the DOS window. 4, set the virtual directory editing server file (x: /tomcat/conf/server.xml) Because you want to read the information of the Server file when Tomcat is started, you must restart Tomcat after changing the Server file.

For example: We intend to establish a Myjsp's virtual directory, just add the following code in the server.xml file: where Path is the virtual directory we want to build, DOCBASE is the location on the hard disk. 5. Try the results of our previous work to edit a simple small example to test whether our virtual directory is available. Refresh.jsp (c: /myjsp/refresh.jsp) <% @ Page language = "java"%> <% @ page import = "java.util.date"%>

Auto Refresh <% response.setheader ("Refresh", "5");%>

Auto Refresh EXAMPLE

Refresh Time: 5 Sencords

Now Time Is: <% = new date ()%>

Type http; // localhost: 8080 / myjsp / refresh.jsp, huh, huh, you can see the effect. 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 class content, here, I select the virtual directory D: / JSP / WebApp Server.xml setting:

Edit the following code with the middle:

Test

Test

Test

/ TEST

among them,

Test

Description Class files are TEST

/ TEST

Note To the declared servlet "map" on the 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 servlet is successful. If you want to run on another directory, then the principle is the same!!

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

New Post(0)