Bit by bit about Tomcat (architecture, process of handling HTTP requests, installation and configuration, directory structure, setting compression and support for Chinese filenames, and the origin of the name Catalina ...) such as

Source: Internet
Author: User
Tags browser cache clear browser cache

Summarizes Tomcat's architecture, process for handling HTTP requests, installation and configuration, directory structure, setting compression and support for Chinese file names, andThe origin of the name Catalina ... such as
Tomcat and JVM:A tomcat will only start a JVM, all WebApps a JVM process, so system.exit () will cause an impact on other apps in the same Tomcat. Tomcat launches the JVM by invoking the configured JDK or JRE.
Architecture:
Server:A server element represents the entire Catalina servlet container. (Singleton)
Service: It consists of one or more connector, and an engine that handles all customer requests received by connector.
Connector:
    • Tomcat has two typical connector, one that listens directly to HTTP requests from browser, and one that listens for requests from other webserver
    • Coyote http/1.1 Connector listens for Http requests from customer browser at port 8080
    • Coyote JK2 Connector listens for servlet/jsp proxy requests from other webserver (Apache) at Port 8009

Engine
    • The engine can be configured with multiple virtual hosts, each hosting a domain name
    • When the engine obtains a request, it matches the request to a host and then gives the request to the host to handle
    • The engine has a default virtual host that, when the request cannot be matched to any host, is given to the default host for processing

Host
    • Represents a virtual host, which matches each virtual host with a network domain name
    • One or more web apps can be deployed under each virtual host, each Web app corresponds to a context with a context path
    • When host obtains a request, it matches the request to a context and then gives the request to the context to process
    • The matching method is "longest match", so a path== "" context will be the default context for that host
    • All requests that cannot match the path names of other context will eventually match that default context

Context
    • A context corresponds to a Web application, and a Web application consists of one or more servlets
    • The context will be loaded into the Servlet class based on the profile $catalina_home/conf/web.xml and $webapp_home/web-inf/web.xml when it is created
    • When the context obtains the request, it looks for the matching servlet class in its own mapping table (mapping table)
    • If found, executes the class, obtains the requested response, and returns

another frame of composition:

The process by which Tomcat server processes an HTTP request

Suppose the request from the customer is:

http://localhost:8080/wsota/wsota_index.jsp

1) The request is sent to the native port 8080, where the Coyote http/1.1 connector that is listening is obtained
2) connector the request to the engine of the service it is working on and waits for a response from the engine
3) The engine obtains the request localhost/wsota/wsota_index.jsp, matches all the virtual host hosts it owns
4) The engine matches the host named localhost (even if it does not match the request to the host processing, because the host is defined as the engine's default host)
5) localhost host gets the request/wsota/wsota_index.jsp, matching all the context it owns
6) host matches to the context where the path is/wsota (if the match is not matched, the request is given to the context of the path named "" to process)
7) path= "/wsota" The context gets the request/wsota_index.jsp, in its mapping table to find the corresponding servlet
8) context matches to a servlet with a URL pattern of *.jsp, corresponding to the Jspservlet class
9) constructs the HttpServletRequest object and the HttpServletResponse object, calling Jspservlet's Doget or Dopost method as a parameter
) context returns the HttpServletResponse object to host after it has finished executing
) host returns the HttpServletResponse object to the engine
) engine returns the HttpServletResponse object to connector
Connector return the HttpServletResponse object to the customer browser


installation and configuration:
  1. Download: tomcat.apache.org (sub-UNIX and Windows edition)
  2. Unzip to the Windows or UNIX directory
  3. Configuration port: Server.xml
  4. Configure the Tomcat login username password: tomcat-user.xml,
    <tomcat-users>
    <user name= "admin" password= "admin" roles= "Admin-gui,manager-gui"/>
    </tomcat-users>
  5. Configure the JDK, configure the JAVA_HOME environment variable
  6. Modify Port: <connector port= "" "protocol=" http/1.1 "....../>

    • Start :
      • Windows:startup.bat (the pause command can be added at the end of the file for easy viewing of startup results)
      • Unix:./startup.sh (watch Log:tail-f Catalina.log)
    • Close :
      • Windows:shutdown.bat
      • Unix:./shutdown.sh

Tomcat directory structure :
Bin---Store tomcat startup shutdown program
conf---Storing the Tomcat configuration file
lib---Tomcat run requires jar package
Logs---tomcat log files
WebApps---Web site publishing directory (all sites can be published to this directory)
Work ---Storage project runtime, generate data file (JSP translation servlet, session persisted data)
site root directory:
-------Static Web resources, JSP
-------Web-inf Directory
-------Classes Directory (save, class file)
--------Lib directory (Jar package is required for the current site)
--------Web. XML (website configuration file)
* Web-inf directory is not required, no Java Dynamic program code, can not web-inf directory
* Resources in the Web-inf directory cannot be accessed directly by the browser
how to set up Tomcat compression:
To set the response data compression by setting Tomcat/conf/server.xml
<connector port= "protocol=" http/1.1 "
connectiontimeout= "20000"
redirectport= "8443" compression= "on" compressionminsize= " the" compressablemimetype= "Text/html,text/xml,application/javascript,text/css,text/plain,application/jso n "/>
Note: Compressionminsize recommended values between 150 and 1000Clear Browser cache, restart Tomcat
support for downloading a file named Chinese:<connector port= "8080" uriencoding= "Utf-8" protocol= "http/1.1"connectiontimeout= "20000"redirectport= "8443"/>
The origin of the name Catalina:
The name "Catalina," according to Craig McClanahan, who designed the original architecture of the servlet container, C An is attributed to three things:his-Catalina island (despite never have visited it), his cat's habit of hangi Ng around the computer while he is writing the code, and the consideration, at an early stage of development, of building Tomcat on a server framework called Avalon, which are the name of the town on Catalina Island.
Catalina provides Tomcat ' s actual implementation of the servlet specification; When you start up your Tomcat server, y Ou ' re actually starting Catalina.Https://www.mulesoft.com/tcat/tomcat-catalina
Tomcat enable HTTPS (Generate certificate, configure Tomcat Server): http://blog.csdn.net/clementad/article/details/46820997

(original articles, reproduced please indicate the CSDN blog from Clement-xu. )

Copyright NOTICE: This article is the original article, reprint please indicate the CSDN blog which is transferred from Clement-xu.

Bit by bit about Tomcat (architecture, process of handling HTTP requests, installation and configuration, directory structure, setting compression and support for Chinese filenames, and the origin of the name Catalina ...) such as

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.