Embedding Servlets

                                                                                                                                                                                                                                                                                                                                      Back to [Book]     [Topic]

Embedding Servlets

Web Server supports the <servlet> tag. This tag enables you to embed servlet output in an .shtml file. No configuration changes are necessary to enable this behavior. If SSI and servlets are both enabled, the <servlet> tag is enabled.

The <servlet> tag syntax is slightly different from that of other SSI commands in that it resembles the <APPLET> tag syntax:

<servlet name=
         _name_ code=
         _code_ codebase=
         _path iParam1_=
         _v1_
          _iParam2_=
         _v2_>
<param name=
         _param1_ value=
         _v3_>
<param name=
         _param2_ value=
         _v4_>
.
.
</servlet>  

If the servlet is part of a web application, the code parameter is required and other parameters are ignored. The code parameter must include:

  • The value of the url-pattern element defined in the web.xml file for the web application. For more information about web.xml, see the Java Servlet 2.4 specification (Chapter SRV .13, “Deployment Descriptor”). You can find the specification at http://java.sun.com/products/servlet/download.html.
  • The value of the uri attribute defined in the web-apps.xml file for the web application.
    For example, say you want to include the following servlet in your .shtml SHTML file:
    <servlet name=pparams code="/PrintApp/PrintParams">
    </servlet>
    

    You need to include the following definition in your web-apps.xml file:

    <web-app uri="/PrintApp" dir="/iws60/https-server.iplanet.com/acme.com/webapps/PrintApp"/>
    

    You also need to include the following definition in your web.xml file:

    <servlet>
        <servlet-name> pparams </servlet-name>
        <servlet-class> PrintPackage.PrintParams </servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name> pparams </servlet-name>
        <url-pattern> /PrintParams </url-pattern>
    </servlet-mapping>
    

    You must also include any servlet initialization parameters in the web.xml file.

For legacy servlets, the code parameter specifies the .class file for the servlet and is required. The codebase parameter is required if the servlet is not defined in the servlets.properties file and the .class file is not in the same directory as the HTML file containing the <servlet> tag. Legacy servlets must be configured in the default virtual server and do not require a web.xml file.

Labels

java java Delete
server server Delete
sun sun Delete
webserver webserver Delete
application application Delete
system system Delete
webtier webtier Delete
guide guide Delete
webserver70 webserver70 Delete
sunjava sunjava Delete
+devguide +devguide Delete
developers developers Delete
web web Delete
developersguide developersguide Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

Sign up or Log in to add a comment or watch this page.


The individuals who post here are part of the extended Sun Microsystems community and they might not be employed or in any way formally affiliated with Sun Microsystems. The opinions expressed here are their own, are not necessarily reviewed in advance by anyone but the individual authors, and neither Sun nor any other party necessarily agrees with them.

Copyright 1994-2009 Sun Microsystems, Inc.
Powered by Atlassian Confluence
Sun Guidelines on Public Discourse Privacy Policy Terms of Use Trademarks Site Map Employment Investor Relations Contact