Tomcat composition and principles [go]

Source: Internet
Author: User
After Tomcat is installed, open the directory. The following structure is displayed:

Bin: stores server scripts;

Conf: stores configuration files;

Lib: stores the required jar files;

Wabapps: stores the web applications to be released and their deployment files;

Work: stores class files generated by JSP file encoding and encoding;

Logs: stores log files;

In the conf directory, you can see the Catalina directory, context. XML, Web. XML, server. XML, and so on (some are not very important and will not be listed ).

Server. XML is called the main configuration file or global configuration file of Tomcat. It completes two tasks:
1) provide initial configuration of Tomcat Components
2) describe the structure and meaning of Tomcat, so that Tomcat can be started and built by instantiating components.

Important elements described in server. xml include server, service, connector, engine, host, and context.
The structure is as follows:

Their usefulness is:

Server:
The top-level element. The root element of the configuration file indicates that the entire servlet container or Tomcat server contains multiple listener, one globalnamingresources and one service.

Service:
A set of ctor and an engine. This set of connector shares an engine to process requests received by all connector and process client requests obtained by <connector>.

Listener group:
Listener for managing Tomcat lifecycle and global resources

Globalnamingresources:
Configure the system's JNDI (Java Naming and Directory Interface)

Connector group:
A connector represents an interface between external customers. It listens to customer requests on a specified interface, submits the obtained requests to <engine> for processing, and then returns the processing results to the customer.

Engine:
Engine to process all customer requests in <service>. Specifically, after obtaining a request from <connectors>, match the request to a
Host group:
A vm processes requests from a specific host. Generally, one or more web applications can be configured for each VM. Each web application corresponds to one <context>,
Context group:
Web application group. Each web application consists of one or more servlets. When <context> receives a request, it maps to/CONF/web. the <servlet> element in the XML file matches a servlet class for processing and returns. When a web application is initialized, it loads each servlet class defined in Web. XML with its classloader object.

Start Tomcat and enter http: // localhost: 8080/in the browser to open the default page of Tomcat. In fact, this page is under the tomcat installation directory:/webapps/root/index. JSP;/webapps is the directory used by the Tomcat server to store web applications. Each web application will create its own subdirectory here, the default directory of the newly installed Tomcat server virtual host is/webapps/root, so files under this directory are opened by default. The process is as follows:
The Web. xml configuration file in the/conf directory contains the following Configuration:
<Welcome-file-List>
<Welcome-File> index.html </welcome-File>
<Welcome-File> index.htm </welcome-File>
<Welcome-File> index. jsp </welcome-File>
</Welcome-file-List>
It is used to configure the homepage. Tomcat will find the content in the <welcome-File> tag in order as the homepage. In our directory, it only finds index. jsp, so it will be displayed;
But we cannot put all web programs in the root. Therefore, we need to change the Tomcat virtual directory;

To set the virtual path, you must. adding a <context> sub-element to the Web application in the Steps:
1) Add the following code in <Context docbase = "D:/MyApp" Path = "/MyApp" reloadable = "true"> </context>
2) put all the files in the prepared web application in the following directory: D:/MyApp/test
3) Restart Tomcat and enter "http: // localhost: 8080/test" in the browser to test the function.

Web. xml
In the Tomcat directory,/conf can be used to configure different context environments for different applications. It is used to map servlets;
The/WEB-INF directory under the root directory of a Web application also has a web. XML. When deploying a web application, it always loads/CONF/Web first. XML, and then load the/WEB-INF/web. XML file, but in the processing process, you always use your own web. xml configuration file. If it cannot be processed, it is handed over to the Tomcat web. XML file.
http://localhost:8080/wsota/wsota_index.jsp
1) The request is sent to the local port 8080, which is obtained by coyote HTTP/1.1 Connector
2) connector submits the request to the engine of the Service to process it, and waits for a response from the engine.
3) The engine obtains the request localhost/wsota/wsota_index.jsp, matching all the virtual host hosts it owns.
4) The engine matches the host named localhost (the request is handed over to the host even if the match fails, because the host is defined as the default host of the engine)
5) the localhost obtains the request/wsota/wsota_index.jsp and matches all the context
6) The host matches the context in the/wsota path. (if no match is found, submit the request to the context with the path name "" for processing)
7) obtain the request/wsota_index.jsp from the context of Path = "/wsota" and find the corresponding servlet in its mapping table.
8) the context matches the servlet whose URL pattern is *. jsp, which corresponds to the jspservlet class.
9) construct the httpservletrequest object and the httpservletresponse object, and call the jspservlet doget or dopost method as parameters.
10) Context returns the httpservletresponse object after execution to the host
11) The host returns the httpservletresponse object to the engine.
12) the engine returns the httpservletresponse object to Connector
13) connector returns the httpservletresponse object to the client browser.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.