tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Craig R. McClanahan" <>
Subject Re: servlet url at init time
Date Fri, 01 Feb 2002 22:17:54 GMT

On Fri, 1 Feb 2002 wrote:

> Date: Fri, 1 Feb 2002 17:13:07 +0100
> From:
> Reply-To: Tomcat Users List <>
> To:
> Subject: servlet url at init time
> Hello all,
> I would like to know the URL of a servlet _in its init method_:
> I need it to know how it is called without having to tell it via a
> config file...
> I know how to get it when dealing with doGet or doPost, but can't
> find any api at init time :(

There is no such API, but see below for part of the answer.

> did I miss something?

Keep in mind that a servlet doesn't have to have "a" URL -- you can map as
many different URL patterns as you like to it.  Therefore, if you *really*
want to know, you can use an XML parser to read the "/WEB-INF/web.xml"
resource and figure them all out.  You can find out your own
<servlet-name> (in servlet 2.3 at least) from the ServletConfig object, so
it's just a matter of looking for all the <url-pattern> values that map to
this name.

This still only tells you the context-relative part of the URL -- the
context path is not visible until a request comes in.

> thanks
> --
> Joseph


> This message and any attachments (the "message") is
> intended solely for the addressees and is confidential.
> If you receive this message in error, please delete it and
> immediately notify the sender. Any use not in accord with
> its purpose, any dissemination or disclosure, either whole
> or partial, is prohibited except formal approval. The internet
> can not guarantee the integrity of this message.
> BNP PARIBAS (and its subsidiaries) shall (will) not
> therefore be liable for the message if modified.
>                 ---------------------------------------------
> Ce message et toutes les pieces jointes (ci-apres le
> "message") sont etablis a l'intention exclusive de ses
> destinataires et sont confidentiels. Si vous recevez ce
> message par erreur, merci de le detruire et d'en avertir
> immediatement l'expediteur. Toute utilisation de ce
> message non conforme a sa destination, toute diffusion
> ou toute publication, totale ou partielle, est interdite, sauf
> autorisation expresse. L'internet ne permettant pas
> d'assurer l'integrite de ce message, BNP PARIBAS (et ses
> filiales) decline(nt) toute responsabilite au titre de ce
> message, dans l'hypothese ou il aurait ete modifie.
> --
> To unsubscribe:   <>
> For additional commands: <>
> Troubles with the list: <>

To unsubscribe:   <>
For additional commands: <>
Troubles with the list: <>

View raw message