All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class org.apache.jserv.JServSSI

java.lang.Object
   |
   +----javax.servlet.GenericServlet
           |
           +----javax.servlet.http.HttpServlet
                   |
                   +----org.apache.jserv.JServSSI

public class JServSSI
extends HttpServlet
JServSSI provides support for including dynamic servlet output from within HTML documents via the <SERVLET> tag.

Configuring the Apache Server

In order to take advantage of the capabilities provided by this class, you must first configure your Apache web server so that it knows how to pass documents which will contain <SERVLET> tags to this class.

Typically, this is done by naming files with SERVLET tags with a ".jhtml" extension, and adding the following lines to your Apache server configuration file:

   # enable <servlet> tag in .jhtml files
   AddHandler jhtml-parser .jhtml
   Action jhtml-parser /servletDirectory/org.apache.jserv.JServSSI
   
where servletDirectory is the URI from which your servlets are accessed, as designated by the "ServletAlias" directive. (This is often "/servlets".)

Including Servlets in HTML Pages

The <SERVLET> and </SERVLET> tags

Servlet output may be included in an HTML document by use of the <SERVLET> tag. For example, to embed the output of the demo "HelloWorldServlet" servlet in an HTML page, you might write the following:

   ... (some HTML code) ...
   <SERVLET CODE="HelloWorldServlet.class">
   Your web server has not been configured to support servlet tags.
   </SERVLET>
   ... (more HTML code) ...
   

When this page is served from the web server, the code above will be replaced with the output of HelloWorldServlet. If you see the message between the tags instead, there is a problem with your server configuration. If this happens, check to make sure your file has a ".jhtml" extension and that the Apache server is configured as described above.

Two attributes are used by the SERVLET tag, and they are roughly equivalent:

  1. The CODE attribute may be set to the name of a class file (the ".class" extension is optional) containing the servlet to be run. Currently, this servlet must be installed in the same directory as the other servlets, not in the directory where your HTML resides.

  2. The NAME attribute may also be set to the name of the servlet to be run (with no class extension).

In some implementations of SERVLET tags, if both NAME and CODE attributes are set, the servlet designated by CODE will then become available for future use under the symbolic named designated by the NAME attribute. This is not currently supported.

Note that both the <SERVLET> and </SERVLET> tags must be present.

The <PARAM> tag

You may send parameters to a servlet via the PARAM tag, which should be placed between the <SERVLET ... > and </SERVLET> tags, like so:

   <SERVLET CODE="MyServlet.class">
   <PARAM NAME="param1" VALUE="valueOfParam1">
   <PARAM NAME="anotherParam" VALUE="valueOfAnotherParam">
   </SERVLET>
   

You could then access these parameters from your servlet as follows:

   public void doGet(HttpServletRequest req, HttpServletResponse res)
       throws ServletException, IOException
   {
       String param1 = req.getParameter("param1");
       String anotherParam = req.getParameter("anotherParam");
   }
   

Notes

Attribute values
Attribute values, NAME and VALUE in the PARAM tag may be a single word (NAME=xyz value=1) or must be enclosed in quotes if they contain whitespace (NAME=xyz VALUE="This is a test").

Case sensitivity and SGML
This class does not care about case when reading SGML tags or their attributes, so uppercase, or lowercase, or any combination thereof may be used. The text in attribute values is not translated to upper- or lowercase but is passed on intact.

Error handling
To simplify error detection and correction, exceptions thrown by JServSSI or called servlets are printed, enclosed in comments ("<!-- ... -->"), in the HTML output.

Known bugs
Currently, the parameters set for the first servlet on a page will still be set in the next servlet.

Author:
Roger Zeng, Tim Williams
See Also:
HttpServlet

Constructor Index

 o JServSSI()

Method Index

 o destroy()
Clean up servlet when finished.
 o doGet(HttpServletRequest, HttpServletResponse)
Process named page HTML passed found via getPathTranslated().
 o doPost(HttpServletRequest, HttpServletResponse)
Handle POST the same as GET.
 o getServletInfo()
Return information about JServSSI to caller.
 o init(ServletConfig)
Initialize JServSSI.

Constructors

 o JServSSI
 public JServSSI()

Methods

 o init
 public void init(ServletConfig config) throws ServletException
Initialize JServSSI.

Parameters:
config - servlet configuration, stored by superclass
Throws: ServletException
passed on from superclass
Overrides:
init in class GenericServlet
 o doPost
 public void doPost(HttpServletRequest req,
                    HttpServletResponse res) throws ServletException, IOException
Handle POST the same as GET. This method is simply a call to doGet().

Parameters:
req - encapsulates the request to the servlet
resp - encapsulates the response from the servlet
Throws: ServletException
will be passed on from included servlets
Overrides:
doPost in class HttpServlet
See Also:
getPathTranslated, doGet
 o doGet
 public void doGet(HttpServletRequest req,
                   HttpServletResponse res) throws ServletException, IOException
Process named page HTML passed found via getPathTranslated().

Parameters:
req - encapsulates the request to the servlet
resp - encapsulates the response from the servlet
Throws: ServletException
will be passed on from included servlets
Overrides:
doGet in class HttpServlet
See Also:
getPathTranslated
 o destroy
 public void destroy()
Clean up servlet when finished.

Overrides:
destroy in class GenericServlet
 o getServletInfo
 public String getServletInfo()
Return information about JServSSI to caller.

Returns:
string explaining this what this servlet does and referring the user to the javadocs.
Overrides:
getServletInfo in class GenericServlet

All Packages  Class Hierarchy  This Package  Previous  Next  Index