Server Side Include in GlassFish
Friday Jul 11, 2008
Server Side Include (SSI) allows including dynamic contents in html. SSI and CGI were very popular before the the appearance of JSP and PHP. The SSI code in GlassFish workspace is based on Tomcat. In GlassFish v3, SSI will be a supported feature. Let us look at a very simple example.
Create a SSI file
In our example, we create aindex.shtml which
- includes the content of
header.html, - prints a Hello message with server side timestamp, and
- executes a command say, uname (or any command in your operating system).
<!--#include virtual="header.html"-->
<br>Hello, it is <!--#echo var="DATE_LOCAL"-->.
<br>Result: <!--#exec cmd="uname"-->
Note that the extension shtml is configurable
in web.xml (see servlet-mapping below).
Enable SSI processing
The SSI processing can be enabled in a war file by adding
SSIServlet et al in web.xml as follows:
<web-app>
<servlet>
<servlet-name>ssi</servlet-name>
<servlet-class>org.apache.catalina.ssi.SSIServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ssi</servlet-name>
<url-pattern>*.shtml</url-pattern>
</servlet-mapping>
<mime-mapping>
<extension>shtml</extension>
<mime-type>text/html</mime-type>
</mime-mapping>
</web-app>
One can find more details about the configuration of SSIServlet in
the section below.
Alternatively, one can enable SSI by uncommenting the corresponding sections
in default-web.xml.
Note that the mime-mapping is to notify the browser
that the result of shtml file is of content-type: text/html.
If you don't specify this, then GlassFish will try to get the
mime-type from default-web.xml or
the default in the system.
Configuration of SSIServlet
One can configure SSIServlet by specifying the init-param as follows:
| init-param | Type | Description | Default |
|---|---|---|---|
| buffered | boolean (or String converted to boolean) | whether the output should be buffered | false |
| debug | int | represents debug level | 0 (no debug) |
| expires | Long | expiration time in seconds | do not set "Expires" header in Http Response |
| inputEncoding | String | encoding for SSI input if there is no URL content encoding specified | server platform encoding |
| isVirtualWebappRelative | boolean (or String converted to boolean) | whether the "virtual" path of "#include" directive is relative to content-root | false (means relative to the given SSI file) |
| outputEncoding | String | encoding for SSI output | UTF-8 |










