Server-Side Includes (SSI) give you the ability to embed instructions to the server inside an HTML document. The instructions are given using extensions to the HTML tag language. A special file extension, .shtml, signals the server that the document contains SSI directives. The server parses the document, executing SSI code in-line. Results are embedded in the document before it is served to the client.
Server-side includes can be as simple as embedding boilerplate text (such as copyright notices) or as powerful as calling executable programs (such as servlets). Traditionally, there have been two considerations for web administrators in allowing server-side includes: security and performance. The security issue usually centers around whether you want document providers issuing executables on the server. The performance issue focuses on the impact of having a heavily loaded server parsing documents prior to serving them.
<--#command tag1="value1" -->
Notes:
Most commands take only one tag at a time.
There should be no spaces between the <-- and the #.
The set of standard commands are:
errmsg
sizefmt
bytes
) or an
abbreviated format of megabytes, kilobytes, and bytes (abbrev
).timefmt
For example:
<!--#config errmsg="[Error occurred while parsing document.]" -->
<!--#config sizefmt="bytes" -->
<!--#config timefmt="%H:%M:%S" -->
virtual
file
virtual
, the file
tag simply specifies the name
of the file. When used alone, it specifies the path and name of the file relative to
the current directory (the string "../" cannot be used).For example:
<!--#include virtual="/pathfromdocdir/" file="copyright.html" -->
<!--#include file="data/table.html" -->
var
For example:
<!--#echo var="DATE_LOCAL" -->
virtual
file
For example,
<!--#fsize virtual="/shortcut/" file="moon.html" -->
virtual
file
For example:
<!--#flastmod file="/home/nancy/JavaWebServer1.1/public_html/moon.html" -->
cmd
cgi
For example:
<!--#exec cgi="/cgi-bin/myscript.cgi" -->
For more information on NCSA Server-Side Includes, see their on-line tutorial.
The JavaTM Web ServerTM provides support for both standard and servlet-specific SSI commands. The servlet-specific SSI commands provide a convenient way to load and invoke servlets. Both local and remote servlets can be used in this manner.
The syntax of a SSI tag for inclusion of servlets differs from the NCSA syntax discussed above but is very similar to the applet tag. For example:
<servlet code=DateServlet.class codebase=http://blitz/ initParam1=val1 / initParam2=val2> <param name=serviceParam1 value=val3> <param name=serviceParam2 value=val4> . . </servlet>The code is the name of the class file that is to be loaded. The codebase parameter is optional, if present it could refer to a remote location for the servlet. The rest of the line in the first servlet tag refers to the init parameters for the servlet. A list of name-value pairs can also be specified for request parameters before the closing /servlet tag.
In the example presented above, the contents of the file up to the servlet tag would be sent to the client unmodified. Then the DateServlet will be loaded from http://blitz and invoked with the appropriate init and request parameters. The output of the DateServlet is embedded into the response. The contents of the file after the ending servlet tag is then appended unmodified.
http://Server_Host_Name:9090
Top java-server-feedback@java.sun.com |
Copyright © 1997
Sun Microsystems, Inc. All Rights Reserved. |