For example, to associate the class mypackage.FooServlet with the name foo, add the following line to servlet.properties:
foo.code=mypackage.FooServlet
Continuing with the example above, to map the request URL http://<host>/foo.html to the servlet named foo, add the following line to rules.properties:
/foo.html=foo
For example, the servlet foo mentioned above could be accessed by either of the following URLs:
http://<host>/foo.html
http://<host>/servlet/foo
The syntax for the servlet tag is:
<servlet name=ServletName code=ServletCode.class initParam1=initArg1 initParam2=initArg2 ...> <param name=param1 value=val1> <param name=param2 value=val2> . . . </servlet>
The server first trys to invoke the servlet with the name referenced by the
name field. If this fails or if no name is provided it attempts to load the
servlet based on the code
field, passing any remaining fields
within the <servlet>
tag to the servlet as initialization
arguments. If the
server loads the servlet and a name was specified, the server keeps the servlet
loaded so that the next time the servlet is accessed it is not reloaded. If
no name is specified, the server reloads the servlet each time it is accessed.
Once the server has a handle to the servlet, either by referencing it from
the name or loading it, it calls service on the servlet. The name value pairs
specified in the html file with the <param>
tag are accessible to the servlet using
the standard getParameter
and getParameters
methods on the ServletRequest object
passed to the servlet in service.
Everything the servlet writes to ServletResponse.getOutputStream()
gets written
out to the client as part of the document the client requested. The servlet's output appears in the document at the location where the servlet tag was embedded.