Tomcat SSI Configuration

Source: Internet
Author: User
Tags comments local time unique id
SSI How to

SSI (Server Side Includes) is The instructions placed in the HTML page (directives) are evaluated on the server while the HTML page is being used. This allows you to add new content to an existing HTML page without having to use a CGI program or other dynamic technology to generate the entire page.

When you use Tomcat as your HTTP server and require SSI support, you can add SSI support to Tomcat. It's usually done when you don't want to run a Web server like Apache. The

Tomcat SSI supports the implementation of the same directives as Apache. For information about using SSI directives, see Apache Introduction to SSI.

Tomcat's support for SSI is accomplished by using a servlet or filter. You have to choose one of them to support your SSI and not use two at a time.

The servlet-based SSI is accomplished by implementing org.apache.catalina.ssi.SSIServlet. In the custom of SSI, the servlet is then mapped to a URL that ends with "*.shtml." The

SSI based on filters is accomplished by implementing org.apache.catalina.ssi.SSIFilter. By rule, this filter filters all URLs that end with "*.shtml", and you can use "*" Maps to filter all URLs, but it will decide whether to enable SSI based on different file types (MIME types). Using the initial value ContentType lets you decide whether to use SSI to process JSP, Javascript, or other content pages. The

Setting by default is Tomcat does not automatically enable SSI.


warning --ssi directives can A program used to perform external to the Tomcat JVM. If you are using Java SecurityManager, it can bypass the security policy configuration in your catalina.policy.

Rename the $catalina_base/server/lib/servlets-ssi.renametojar to $CATALINA _base/server/lib/servlets-ssi.jar.

If you choose to use a servlet-based SSI, reactivate the servlet and servlet-mapping definitions in $catalina_base/conf/web.xml that are commented out on SSI.

If you choose a filter based SSI, clear activation $CATALINA _base/conf/web.xml The settings for the filter and filter-mapping for SSI.

Servlet Settings

There are several Servlet start parameters that you can use to configure The behavior of the SSI servlet. Buffered -the output of this servlet should not be buffered. (0=false, 1=true) defaults to 0 (false). Debug -The verbosity of the queued message for this servlet log. The default is 0. Expires -the number of seconds before a page with SSI directives fails. The default behavior is to evaluate the SSI directives used for each request. Whether the isvirtualwebapprelative -"virtual" SSI instruction path should be interpreted relative to the context root rather than server root. (0=false, 1=true) defaults to 0 (false). inputencoding -If you cannot determine the literal encoding of the resource being invoked, the encoding that SSI should use. The default value is the text encoding of the system. outputencoding -The text encoding of the output result, and the default value is UTF-8.


Filter settings

The performance of the filter can be adjusted by modifying several different initial values. ContentType -use a regular expression to set that type of Web page should invoke SSI. When deciding on regular expressions, don't forget that you can have text-encoded options in the definition of the content type of a Web page, and its standard is: "Mime/type; Charset=set ", where Charset=set is the selected item. The default value for contenttype is: "text/x-server-parsed-html (;. *)?". Debug -The verbosity of the error message in this servlet log. The default is 0. expires -the number of seconds before a page with SSI directives fails. The default behavior is to evaluate all SSI directives for each request. isvirtualwebapprelative -the "virtual" SSI instruction path should be interpreted as relative to the context root or relative to server root (0=false, 1=true) by default is 0 ( False).

Tomcat Allow SSI directives

SSI is implemented by embedding HTML Directives to implement dynamic Web pages. These instructions are HTML-like annotations in HTML, which, when run by Tomcat, will replace it with the content of the response. The standard format for these directives is:

<!--#directive [Parm=value]-->

Valid directives are: config -<!--#config timefmt= "%B%Y"--> format for specifying the time date or other content of SSI output echo -<!--#echo var= "V Ariable_name "--> Replace the specified number exec -the command for running the system include -<!--#include virtual=" File-name "--> insert Rong flastmod -<!--#flastmod file= "filename.shtml"--> file Last modified fsize -<!--#fsize file= " filename.shtml--> File Size printenv -<!--#printenv--> Print all environment variables set -<!--#set var= "foo" Valu E= "Bar"--> is used to assign values to user-defined variables if elif endif else -for conditional judgment, such as: <!--#config timefmt= "%A"-->
<!--#if expr= "$DATE _local =/monday/"-->
<p>meeting at 10:00 on mondays</p>
<!--#elif expr= "$DATE _local =/friday/"-->
<p>turn in your time card</p>
<p>yoga class at Noon.</p>

Read more SSI related content:

Getting Started with Apache SSI


The SSI Servlet now supports the following variables:

Variable name Description
Auth_type The method used to authenticate the user can be: BASIC, FORM, etc.
Content_length The length of data from form, the number of bytes or characters
Content_Type MIME type, such as "text/html"
Date_gmt Now the international Standard Time GMT
Date_local local time
Document_name File name of the call
Document_uri Virtual path to File
Gateway_interface The server displays a supported CGI version, such as "cgi/1.1" if CGI is activated.
Http_accept All allowed MIME types
Http_accept_encoding Lists the compression methods allowed by all clients
Http_accept_language List languages accepted by all clients
Http_connection Client-accepted connection management methods, such as "close" or "keep-alive"
Http_host Web site that the user requests to visit
Http_referer Link to the Web page address, the user from the Web page
Http_user_agent The name of the browser
Last_modified The last modification time of the current file
Path_info Path information passed to the server
Path_translated Converted Path_info Path
Query_string Value after "?" in the browser's address bar
query_string_unescaped undecoded query string with the all shell metacharacters escaped with "/"
Remote_addr User's IP address
Remote_host User's URL
Remote_port The port number used by the user
Remote_user Confirmed user name
Request_method The method used by the user to request access, such as "get", "POST", etc.
Request_uri The URL that the user requests to visit
Script_filename The file name of the Web page that the user actually accesses on the server
Script_name The file name of the Web page
Server_addr IP address of the server
server_name The name or IP of the server computer
Server_port Port on which the server waits for user access
Server_protocol protocol used by the server, such as: "http/1.1"
Server_software The number of software names and versions used by the server
unique_id The server and user currently have a unique ID for the start session

Another practical article reads as follows:

In the current Tomcat, sHTML is not supported by default, the need for a certain configuration, in fact, is not very complex, different Tomcat version, configuration methods are different, the reference method is as follows:

tomcat5.x version of the configuration method:

1. Locate the Servlets-ssi.renametojar file in the $catalina_base/server/lib/directory and rename the file to Servlets-ssi.jar
2. Find the Web.xml file in the $catalina_base/conf/directory
3. Delete comments around SSI servlet and servlet-mapping using SSI servlet, delete comments around SSI filter and filter-mapping using SSI filter

The configuration of Tomcat 6 SSI is different from the 5.x version, and the configuration method for Tomcat 6 SSI is described below

TOMCAT6 version of the configuration method:

1. Find the Web.xml file in the $catalina_base/conf/directory
2. Delete comments around SSI servlet and servlet-mapping using SSI servlet, delete comments around SSI filter and filter-mapping using SSI filter
3. There is also a context.xml under the $CATALINA _base/conf/to convert the inside <Context> to <context privileged= "true" >
4. Solve garbled problem
Add the following initial configuration in the SSI servlet configuration in $catalina_base/conf/web.xml:


Where the Utf-8 encoding should be the same as the way your page is encoded.
For more information, please refer to the official configuration instructions

After the configuration above, include files:
<!--#include file= "include.html"-->
<!--#include virtual= "include.html"-->
Before it can be displayed properly.

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: 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.