Establishment of Tomcat environment

Tomcat is another excellent JSP server developed on the basis of sun's jswdk. It not only supports servlet, but also provides the function of web server. As an open source software, Tomcat has its own unique advantages. It can work with most of the current mainstream servers, and has quite high operation efficiency. Through this chapter, readers will see: · the basic concept of Tomcat · how to make Tomcat work with IIS · how to make Tomcat work with Apache · how to set the virtual directory of JSP · how to set Tomcat as a Windows service to run Jakarta Tomcat overview: Tomcat is a servlet container with JSP environment. Servlet container is a shell that can manage and activate servlet runtime according to user behavior. We can roughly divide servlet containers into the following categories: independent servlet containers have a built-in part of the web server. Refers to the case where a Java based web server is used. For example, the servlet container is part of the Java Web server. A separate servlet container is the default mode for Tomcat. However, most web servers are not Java based. Therefore, we can draw the following two container patterns: in-process servlet container, servlet container as a plug-in of web server and the implementation of Java container. The web server plug-in opens a JVM (Java virtual machine) in the internal address space so that the Java container can run internally. If there is a request to call the servlet, the plug-in will take control of the request and pass it on (using JNI) to the Java container. The process content container is very suitable for multi-threaded and single process servers and provides good running speed, but its scalability is insufficient. The out of process servlet container servlet container runs in the address space outside the web server and serves as a combination of the plug-in of the web server and the implementation of the Java container. The web server plug-in and the Java container The JVM uses IPC mechanism (usually TCP / IP) for communication. When a request to call servlet arrives, the plug-in will take control of the request and pass it (using IPC, etc.) to the Java container. The response time of the out of process container or the out of process container engine is not as good as the process content container, but the out of process container engine is better in many other comparable ranges (scalability, stability, etc.). Tomcat can be used not only as a separate container (mainly for development and debugging), but also as an add-on to existing servers (Apache, IIS and Netscape servers are currently supported). Therefore, when configuring tomcat, you must decide how to apply it. If you choose the second or third mode, you also need to install a web server interface. What is the difference between Tomcat and jserv? Is Tomcat a jserv? This is a common misunderstanding. Jserv is a container compatible with servlet api2.0 and used with Apache. Tomc At is a completely rewritten API 2 2 and jsp1 1 compatible container. In addition, Tomcat uses some code written for jserv, especially the Apache interface of jserv, but this is the only thing in common. How do I install the binary version of Tomcat? Very simple, just download zip / tar GZ any compressed file, from http://jakarta.apche.org/download/binindex.html Unzip this file to a directory (e.g. foo), and a subdirectory named "Tomcat" will be generated. Convert to the "Tomcat" directory, set a new environment variable (tomcat_home) to point to the directory of Tomcat you installed: Win32 platform, type: set Tomcat_ HOME=foo/tomcat

UNIX platform: for bash / sh environment, type: Tomcat_ HOME=foo/tomcat; export TOMCAT_ Home "for the tcsh environment, type: setenv tomcat_home foo / Tomcat to set the environment variable java_home to your JDK directory, and then add the Java interpreter to your path environment variable. OK! Now you can run Tomcat and start and close Tomcat as an independent servlet container (mode 1)" bin "The script in the directory starts and closes Tomcat. Start:

Off:

Assuming that the reader has unzipped tomcat, the following directory structure will be obtained:

Tomcat script Tomcat is a java program, so it can be run from the command line after setting several environment variables. However, setting each environment variable used by Tomcat and the following command-line parameters is tedious and error prone. Therefore, the Tomcat development team provides some scripts to make it easy to start and shut down Tomcat. Note: these scripts are just a convenient way to start and shut down Tomcat. You can modify them to customize classpath and environment variables such as path and LD_ LIBRARY_ Path and so on, as long as a correct command line is generated. What are these scripts? The scripts that are most important to the average user are listed below. Tomcat: main script. Set appropriate environment variables, including classpath and Tomcat_ Home and Java_ Home and start Tomcat with the appropriate command line parameters. Startup: start Tomcat in the background. It is an alternative to the "Tomcat start" command. Shutdown: close Tomcat. It is an alternative to the "Tomcat stop" command. The most important script for users is Tomcat (Tomcat. Bat / Tomcat. SH). Other Tomcat related scripts are used as a simple single task oriented entry to Tomcat scripts (setting different command-line parameters, etc.). Take a closer look at Tomcat bat/tomcat. SH, it runs according to the following steps: steps under UNIX: if not specified, speculate Tomcat_ If home is not specified, Java is assumed_ Home setting class_ Path contains: 1. ${tomcat_home} / classes directory (if any) 2. ${tomcat_home} / lib everything 3. ${java_home} / lib / tools jar (this jar file contains the tool javac, and we need javac to process the JSP file) run the Java command with the command line parameters for setting the Java environment variables, and call tomcat.home and org.apache.tomcat.startup.tomcat as the start class. At the same time, pass the command line parameters to org.apache.tomcat.startup.tomcat, for example: execute the operations such as start / stop / run. In addition, this Tomcat The process uses a pointer to server XML path, such as server XML is placed in etc / server_ 1. XML and the user intends to start Apache in the background, type the following command line: bin / Tomcat sh start -f /etc/server_ 1.xml tomcat.xml for Win32 Bat is almost the same as the UNIX version. Especially when it does not speculate on Tomcat_ Home and Java_ The value of home, and do not put all jar files in the classpath. This section of Tomcat's configuration file describes how to use the configuration file server XML and web xml。 We won't include web XML, which goes deep into the details of servlet API, so we will discuss the usage of these two configuration files in Tomcat relational environment. Tomcat configuration is based on two configuration files: 1. Server XML - Tomcat's global configuration file, Two objectives are achieved: (1) provide the initial configuration of Tomcat components (2) Explain the structure and meaning of tomcat, so that Tomcat can start and build itself by instantiating components. The description of structure and meaning is implemented through elements, which will be described below. Server: the most important element in the server.xml file. Server defines a Tomcat server. General readers don't have to worry about it too much. The server element can contain a logger And contextmanager element types. Logger: this element defines a logger object. Each logger has a name to identify it. It also records the output and redundancy level of the logger (describing this log level) and the path containing the log file. Usually, there are the logger of servlet (at ServletContext. Log ()), the logger of JSP and Tomcat runtime. Contextmanager: it describes the configuration and structure of a set of contextinterceptor, requestinterceptor, context and their connectors. The context manager has several accompanying features: a. the debugging level used to record debugging information B. webapps /, conf /, logs / and the basic location of all defined environments. Used to make Tomcat available in Tomcat_ Start in a directory other than home. C. name of working directory: contextinterceptor & requestinterceptor: these interceptors listen for events that occur in contextmanager. For example, contextinterceptor listens for the start and termination events of tomcat, and requestinterceptor monitors the different stages of user requests in its service process. Tomcat administrators don't have to know much about listeners; In addition, developers should know how to implement a "global" operation in Tomcat (such as security and each request log). Connector: indicates a connection to the user, Whether through the web server or directly to the user browser (in a separate configuration). The connector is responsible for managing Tomcat worker threads and read / write requests / responses connected to ports of different users. The configuration of the connector includes the following information: A. handle class B. TCP / IP port on which the handle listens C. TCP / IP backlog context on the handle server port: each context provides a web item pointing to you The subordinate directory of Tomcat. Each context contains the following configurations: a. the path placed by the context can be the path related to the contextmanager home directory B. the debugging level for recording debugging information C. The overloadable flag. When developing a servlet, reload the changed servlet, which is a very convenient feature 2. Web XML -- configuring different relational environments in Tomcat has a small "feature" related to Tomcat and web XML. Tomcat allows users to use the default web XML is put into the conf directory to define the web. XML of all relational environments The default value for XML. When creating a new relational environment, Tomcat uses the default web XML files are used as basic settings and application project specific web XML (placed in the WEB-INF / Web. XML file of the application project) to override these default values.

How to load Tomcat into IIS IIS, that is, Internet information server, is a powerful web server provided by Microsoft. It has good support for ASP, which I believe many readers already know. Now, JSP has become popular. How can IIS support this technology? Readers will get answers from this section. I. installation environment: Windows 2000, IIS 5.0, Tomcat 3.1 download address http://jakarta.apache.org/builds/tomcat/release/v3.1/bin/   isapi_ redirect. DLL download address http://jakarta.apache.org/builds/tomcat/release/v3.1/bin/win32/i386/ Put it in {tomhome} iniisi386isapi_ redirect. DLL 2. First ensure that Tomcat can execute correctly. 3. Connect the following Jakarta. DLL between begin and end Reg file is loaded into the machine, and my Tomcat is installed in C: \ Jakarta Tomcat. You can modify Jakarta according to your own environment Reg file

Save as C: omcatwebappsmyweblasseshelloworld Java, compiled with javac, type in the address bar http://localhost:apache_port/testdir/servlet/HelloWorld Let's see the results. How to set Tomcat to start as a Windows service? As mentioned above, when using Tomcat as a web service, you must start Tomcat manually. Obviously, this is not a suitable method for Tomcat as a web service. Under Linux, you can automatically start Tomcat by modifying the startup script, and under windows, you can set Tomcat as a service for windows. We can use tools to make Tomcat a service of Windows NT / 2000: first, download tools. Here is gservany as an example -- a tool that runs general applications under NT as a service. Download at http://www.advok.com/gservany.html 。 Unzip the zip file to gservany Exe into winntsystem32. 2. Under the command of NT / 2000, enter: gservany - I Tomcat "C: Jakarta Tomcat" "startup. Bat" "C: Jakarta Tomcat" "shutdown. Bat". Where C: Jakarta Tomcat is the installation directory of Tomcat. 3. Start the service manager and you will see that the Tomcat service is installed.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>