"David M. Smith" wrote:

> I have been developing some servlets under the Java Web Server recently
> and I would now like to try running them under Tomcat 3.0.
>
> Under Java Web Server, I am running my servlets via Servlet Aliases /
> Chaining (*.HTML goes through my servlet sort of thing), how do I
> configure this under Tomcat?

Tomcat does not support servlet chaining like JWS does, and there are no plans
to add it -- this design pattern turns out to be fraught with problems.

>  Also is it possible to set up an alias
> that would pass all *.HTML files in a particular directory through my
> servlet?  Other *.HTML files in other directories would be processed
> normally.
>

First, let's assume you wanted to map all HTML files (no matter what directory
they are in) to your servlet -- we will see why this is important in a few
moments.  This is really easy using the deployment descriptor ("web.xml") for
the default context.  Simply add something like this:

    <servlet>
        <servlet-name>SpecialServlet</servlet-name>
        <servlet-class>com.mycompany.myservlets.SpecialServlet</servlet-class>

    </servlet>

    <servlet-mapping>
        <servlet-name>SpecialServlet</servlet-name>
        <url-pattern>*.html</url-pattern>
    </servlet-mapping

Now, every HTML file requested will be handed to your servlet, which can use
the request.getPathInfo() method to find out the name of the page that was
requested.  From there, use ServletContext.getResource() or
ServletContext.getResourceAsStream() to read it, and do whatever you need to.

So how do I do filtering on pages only in one directory?  Two different
approaches are possible -- the simpler one first:

* Configure things as above, but put logic in your
  servlet that the filtering is only done if the path
  information value starts with a particular string.
  Otherwise, the servlet just copies the HTML file
  contents to the response unmodified.  (After all,
  that is all the default file-serving servlet does :-).

* Set up a new web application, mapped to the name
  of your directory, and with a document root pointing
  at that directory.  Now, put the configuration stuff
  above in the web.xml file for the new web application.
  The filtering will only be done for HTML files within that
  directory -- all others will be handled in the usual way.

>
> If there is a better place to ask Tomcat questions, please tell me.
>

For now, Tomcat-specific questions can be addressed to the GENERAL mailling
list at jakarta.org (See the Jakarta web site at <http://jakarta.apache.org>
for subscription information).  Plans are under way to set up a TOMCAT-USERS
list for this type of question.

However, this particular question is actually relevant to all servlet
containers that implement the new 2.2 specification, thanks to the fact that
the web application deployment descriptor format has been standardized.  The
technique described above is portable -- the only thing that varies
significantly between servers is the particulars of how you set up a new
context.

>
> Regards,
> David
> --
> David M. Smith
>

Craig McClanahan

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to