All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object
|
+----javax.servlet.GenericServlet
|
+----javax.servlet.http.HttpServlet
|
+----org.apache.jserv.JServSSI
JServSSI provides support for including dynamic servlet
output from within HTML documents via the <SERVLET> tag.
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
SERVLETtags with a ".jhtml" extension, and adding the following lines to your Apache server configuration file:where servletDirectory is the URI from which your servlets are accessed, as designated by the "# enable <servlet> tag in .jhtml files AddHandler jhtml-parser .jhtml Action jhtml-parser /servletDirectory/org.apache.jserv.JServSSIServletAlias" directive. (This is often "/servlets".)
The
<SERVLET>and</SERVLET>tagsServlet 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
SERVLETtag, and they are roughly equivalent:
- The
CODEattribute 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.- The
NAMEattribute may also be set to the name of the servlet to be run (with no class extension).In some implementations of
SERVLETtags, if bothNAMEandCODEattributes are set, the servlet designated byCODEwill then become available for future use under the symbolic named designated by theNAMEattribute. This is not currently supported.Note that both the
<SERVLET>and</SERVLET>tags must be present.The
<PARAM>tagYou may send parameters to a servlet via the
PARAMtag, 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"); }
- Attribute values
- Attribute values,
NAMEandVALUEin thePARAMtag 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.
public JServSSI()
public void init(ServletConfig config) throws ServletException
public void doPost(HttpServletRequest req,
HttpServletResponse res) throws ServletException, IOException
public void doGet(HttpServletRequest req,
HttpServletResponse res) throws ServletException, IOException
public void destroy()
public String getServletInfo()
All Packages Class Hierarchy This Package Previous Next Index