Tomcat configuration file description, tomcat configuration file

Source: Internet
Author: User
Tags smartstore

Tomcat configuration file description, tomcat configuration file

I have never noticed the role of the configuration file in the conf directory of tomcat in the past tomcat usage. It is the idea of "tailism" and has never been studied in depth. However, I recently encountered many problems related to tomcat configuration, which is very big, so I just sorted it out.

The following configuration files are available: web. xml, tomcat-users.xml, server. xml, and context. xml. First, let's take a look at the functions of these configuration files.

Certificate -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The role of web. xml:

The file format of web. xml is defined in the Servlet specification. Therefore, all Java Servlet Container compliant with the Servlet specification will use it. WhenTomcatWhen an application is deployed (during activation or after the application is loaded), it will read the common conf/web. and then read the WEB-INF/web. xml. (This file generally does not involve modification, so you don't need to know much about it. To be honest, I don't know much about it .)

Certificate -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The role of tomcat-users.xml:

As the name suggests, "uesrs" must be related to users. After opening the file, we can see the annotated code at the bottom of the file:

1 <!--2   <role rolename="tomcat"/>3   <role rolename="role1"/>4   <user username="tomcat" password="tomcat" roles="tomcat"/>5   <user username="both" password="tomcat" roles="tomcat,role1"/>6   <user username="role1" password="tomcat" roles="role1"/>7 -->

Obviously, this is used to configure the user name, password, and user permissions. You only need to add a line after the annotated code to achieve your Configuration:

1 <user username="admin" password="1234" roles="manager-gui"/>

In this way, the administrator user with the username admin and password 1234 is successfully added (manager-gui is the administrator role)

Certificate -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Server. xml:

    In my opinion, the main role of server. xml in today's tomcat version is to process access requests from clients. To understand the role of server. xml, you still need to understand the meaning of each label.

As for the detailed meaning of each label, this article will not point out. If you are interested, please refer to the article specifically summarized by the author for the role of server. xml and point out the general process of server processing an access request.

Tomcat Server processes an http request

Assume that the request from the customer is http: // localhost: 8080/macy/index. jsp.

1) The request is sent to the local port 8080, which is obtained by Coyote HTTP/1.1 Connector.

2) Connector sends the request to the Engine of the Service to process the request, and waits for the response from the Engine.

3) The Engine obtains the request localhost/macy/index. jsp, matchingYesOfYesThe virtual Host.

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 Virtual Host of the Engine ).

5) the localhost obtains the request/macy/index. jsp, matchingYesOfYesContext.

6) The Host matches the Context in the/macy path. (if no match is found, the request is sent to the Context with the path name "" for processing ).

7) obtain the request/index. jsp from the Context of path = "/macy" and find the corresponding servlet in its ing table.

8) the Context matches the servlet with the url pattern *. 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.

It should be noted that the context configuration in Versions later than tomcat 5.5 can no longer be configured in server. xml, but can be configured independently in/conf/context. xml.

Cause: server. xml is a resource that cannot be dynamically reloaded. Once the server is started, you have to restart the server to reload the file. Context. xml

Otherwise, the tomcat server regularly scans the file. Once the file is changed (the timestamp is changed), the file is automatically reloaded without restarting the server.

However, the official website seems to retain the configuration context in server. xml. I think the main reason for this is the compatibility with the old version. (We do not recommend configuring context in server. xml)

Certificate -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Context. xml:

    As shown in the preceding figure, each <Context element represents a single Web application running on a VM.

1 <Context 2 path="/SmartStore" 3 reloadable="false" 4 docBase="D:\SmartStore\workspaceSmartStore\SmartStore\src\main\webapp" 5 workDir="D:\SmartStore\workspaceSmartStore\SmartStore\work" >6     <Logger className="org.apache.catalina.logger.SystemOutLogger" verbosity="4" timestamp="true"/>7 </Context>

1. path:Virtual directory, Note that it is/kaka, which specifies the context root for accessing the Web application, such as http: // localhost: 8080/SmartStore /****
2. docBase: The Path to store the application or WAR file. It can be an absolute or relative path. The relative path is relative to <Host> (the host corresponds to the server. host element in xml)
3. reloadable: If this property is set to true, the Tomcat server will monitor changes in the CLASS file in the WEB-INF/classes and Web-INF/lib directory while running, if a class file is updated, the server automatically reloads the Web application so that we can change the application without restarting tomcat.

4. workDir: When jsp is running, it must first be converted to servlet. When tomcat is used,WorkGenerate a series of folders and. java files and. class files. After setting this attribute, you can change the storage path of the generated java and class files.

Tips: Any number of Context elements are nested in a Host element. The path of each Context must be unique and defined by the path attribute. In addition, you must define a context with path = "". This Context is called the default web application of the VM and is used to process requests that cannot match any Context path.

 

Other labels in context. xml:

<Context path = "/kaka" docBase = "kaka" debug = "0" reloadbale = "true" privileged = "true"> <WatchedResource> WEB-INF/web. xml WEB-INF/kaka. xml </WatchedResource> monitors resource files. xml | kaka. if xml is changed, the application is automatically reloaded and changed. <Resource name = "jdbc/testSiteds" indicates the specified jndi name auth = "Container" indicates the authentication method, generally Container type = "javax. SQL. dataSource "maxActive =" 100 "Maximum number of connections supported by the connection pool maxIdle =" 30 "Maximum number of idle maxIdle connections in the connection pool maxWait =" 10000 "when the connection pool is used up, new request wait time. millisecond username = "root" indicates database username password = "root" indicates database username driverClassName = "com. mysql. jdbc. driver "indicates jdbc driver url =" jdbc: mysql: // localhost: 3306/testSite "/> indicates the URL of the database </Context>

 

The last:

  

Three scopes of context. xml

---------------------------------------------------------------

1. tomcat server level:

Configure in/conf/context. xml

2. Host level:

Add context. xml in/conf/Catalina/$ {hostName} and configure

3. web app level:

Add $ {webAppName}. xml to/conf/Catalina/$ {hostName} and configure it.

 

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.