tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shapira, Yoav" <Yoav.Shap...@mpi.com>
Subject RE: other ways to register a Servlet web application
Date Mon, 02 Aug 2004 13:47:57 GMT

Hi,
I'll get you started, in my email editor and without even trying to
compile this out of laziness:  (But it should be very close)

import org.apache.catalina.Context;
import org.apache.catalina.Engine;
import org.apache.catalina.Host;
import org.apache.catalina.Server;
import org.apache.catalina.ServerFactory;
import org.apache.catalina.Service;
import org.apache.catalina.Wrapper;

public class NotPortable {
  public static void addServlet(Class myServletClass, String urlPattern)
{
    Server server = ServerFactory.getServer();
    Service service = server.findServices()[0];
    Engine engine = (Engine) service.getContainer();
    Host host = (Host) engine.findChildren()[0];
    Context context = (Context) host.findChild("mywebapp");
    Wrapper wrapper = context.createWrapper();
    wrapper.setServletClass(myServletClass);
    wrapper.addMapping(urlPattern);
    wrapper.load();
    context.addChild(wrapper);
    // Optionally context.addServletMapping
}

A production-quality implementation would not hard-code the name of the
webapp, nor would it hard-code the 1st service and 1st host (index [0]
in the above code).  It might also pass init parameters, etc, but this
just an example to give you an idea.

Yoav Shapira
Millennium Research Informatics


>-----Original Message-----
>From: Robert Hunt [mailto:robert-hunt@comcast.net]
>Sent: Sunday, August 01, 2004 2:15 AM
>To: tomcat-user@jakarta.apache.org
>Subject: RE: other ways to register a Servlet web application
>
>Regarding this thread and another I just inquired about
>(http://www.mail-archive.com/tomcat-
>user@jakarta.apache.org/msg132857.html),
>Yoav, would you have a code example?
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org




This e-mail, including any attachments, is a confidential business communication, and may
contain information that is confidential, proprietary and/or privileged.  This e-mail is intended
only for the individual(s) to whom it is addressed, and may not be saved, copied, printed,
disclosed or used by anyone else.  If you are not the(an) intended recipient, please immediately
delete this e-mail from your computer system and notify the sender.  Thank you.


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message