Simple Dynamic/static separation through Tomcat itself
Generally, dynamic/static classification is implemented using Apache + tomcat or Nginx + tomcat. Nginx + tomcat is easy to configure, and Nginx has higher concurrent processing performance; here, only tomcat is used for simple static/dynamic separation.
Tomcat, jboss, jetty, and other containers provide a default servlet: default. The servlet maps static resources from/to/static, and the definition position of the servlet in jboss is: $ {jboss_home}/server/default/deployers/jbossweb. deployer/web. xml; location defined in tomcat: $ {tomcat_home}/conf/web. xml.
The default servlet is a servlet that serves both static resources and directory lists (if the directory list is allowed. It is declared globally in $ CATALINA_HOME/conf/web. xml. The default declaration is as follows: $ CATALINA_HOME/conf/web. xml
<Servlet>
<Servlet-name> default </servlet-name>
<Servlet-class>
Org. apache. catalina. servlets. DefaultServlet
</Servlet-class>
<Init-param>
<Param-name> debug </param-name>
<Param-value> 0 </param-value>
</Init-param>
<Init-param>
<Param-name> listings </param-name>
<Param-value> true </param-value>
</Init-param>
<Load-on-startup> 1 </load-on-startup>
</Servlet>
...
<Servlet-mapping>
<Servlet-name> default </servlet-name>
<Url-pattern>/</url-pattern>
</Servlet-mapping>
Therefore, by default, the servlet is loaded when the webapp is started, the directory list is available, and the log debugging function is disabled.
DefaultServlet allows the following initialization parameters:
| Debug |
Log Level. If you are not a tomcat developer, it is of no use to you. Currently, the valid values are 0, 1, and 11,100. |
| Listings |
If no welcome file exists, do you want to display the directory list? The value can be true or false. Welcome files are part of the servlet api. Warning the List displays directories that contain too many records consume a lot of service performance. A large number of requests to access the large directory list will consume most of the server's resources. |
| ReadmeFile |
If the directory list is allowed, a readme file may be included in the list. This file contains HTML inserted. The default value is null. |
| Globalcomputfile |
If you want to customize the Display Effect of your directory list, you can use an XSL conversion (transformation ). This value is an absolute path file name that can be used for all directory lists. It can be customized by each webapp, or you can declare the default servlet in the web. xml file of your local webapp to cancel the use. The xml file format is shown below. |
| Localcomputfile |
You can also configurelocalXsltFileCustomize your directory list. It should be a relative path file name in the directory where the list is generated. It overwritesglobalXsltFile. If the value exists but the file does not exist, use globalcomputfile. If globalcomputfile does not exist, the default directory list is displayed. |
| Input |
The input buffer capacity (in bytes) when reading resources used for services ). [2048] |
| Output |
The output buffer capacity (in bytes) when reading resources used for services ). [2048] |
| Readonly |
This context is not "read only", so the HTTP commands such as PUT and DELETE will be rejected for execution? [True] |
| FileEncoding |
When file encoding is used to read static resources, [Default platform value] |
| SendfileSize |
If the connector supports sendfile, this parameter indicates the minimum file size used by sendfile (in KB). If you use a negative number, you cannot use sendfile. [48] |
In practice, some static resources of our application can be handed over to the servlet for processing to reduce the server pressure and save resources. For example, we change the access path to static resources from/to/static, for example, http: // localhot/style.css to http: // localhost/static/style.css, and then apply the web. add the following configuration code to the xml file:
<Servlet-mapping>
<Servlet-name> default </servlet-name>
<Url-pattern>/static/* </url-pattern>
</Servlet-mapping>
To achieve simple static/dynamic separation.
For more Tomcat tutorials, see the following:
Install and configure the Tomcat environment in CentOS 6.6
Install JDK + Tomcat in RedHat Linux 5.5 and deploy Java Projects
Tomcat authoritative guide (second edition) (Chinese/English hd pdf + bookmarks)
Tomcat Security Configuration and Performance Optimization
How to Use Xshell to view Tomcat real-time logs with Chinese garbled characters in Linux
Install JDK and Tomcat in CentOS 64-bit and set the Tomcat Startup Procedure
Install Tomcat in CentOS 6.5
Tomcat details: click here
Tomcat: click here
This article permanently updates the link address: