Servlets can be invoked directly by the Java Server through the URL, as discussed in the previous examples. They may also be invoked through an HTML page, with the output generated by the servlet inserted into the HTML page. To do this requires two steps.
First, the file name for the HTML must include a .shtml suffix instead of the usual .html or .htm suffix.
Second, the HTML must include a servlet tag. The tag has the general form shown below:
<servlet name=ServletName code=ServletCode.class
initParam1=initArg1 initParam2=initArg2 ...>
<param name=param1 value=val1>
<param name=param2 value=val2>
.
.
.
</servlet>
Below is an example SHTML file:
Example SHTML Referenced Servlet
<html> <head> <title>SHTML referenced servlet</title> </head> <body bgcolor="#FFFFFF" link="#0000FF" vlink="#800080"> <h1 align="center">Server side Include Example</h1> <p align="center"> <font color="#AA0000"> <servlet code="jbsHelloWorld.class"></servlet> </font> </p> </body> </html>