Article View: aus.computers.java
Article #938Re: finding out serlvet name?
From: Chris Wolfe
Date: Tue, 11 Jan 2000 00:00
Date: Tue, 11 Jan 2000 00:00
30 lines
1824 bytes
1824 bytes
It has been a while since I was rooting through servlets, but it seems
to me that the HttpServletRequest.getServletPath method will get you
what you want. Remember that the same servlet instance could be shared
between more than one URL.
Chris
"Tony F. White" wrote:
>
> Does anyone know how you can find out the name of the current servlet you
> are in.
> and not just the classname (getClass().getName())
> I am sure there has to be a better way because if you look at the log of the
> web server they print out
> [Date + Time ETC] alias/classname : message
> I can do it by using the following but it causes all the servlets to call
> their init() method.
>
> ServletContext context = getServletContext();
> Enumeration names = context.getServletNames();
> String name;
> while (names.hasMoreElements()) {
> name = (String)names.nextElement();
> if (this.equals(context.getServlet(name))) {
> log("wahoo: " + name);
> } else {
> log("Not this one: " + name);
> }
> }
Technical Details
Message-ID:
<387BCBC1.191DF826@globetrotter.qc.ca>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<387bc8b7_2@news.ausmail.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f5d71,37435f9672022420,start X-Google-Attributes: gidf5d71,public X-Google-Thread: 10d6db,37435f9672022420,start X-Google-Attributes: gid10d6db,public X-Google-Thread: 10a146,37435f9672022420,start X-Google-Attributes: gid10a146,public From: Chris Wolfe <cwolfe@globetrotter.qc.ca> Subject: Re: finding out serlvet name? Date: 2000/01/11 Message-ID: <387BCBC1.191DF826@globetrotter.qc.ca> X-Deja-AN: 571426372 Content-Transfer-Encoding: 7bit References: <387bc8b7_2@news.ausmail.com> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii Organization: Queen's University, Kingston Mime-Version: 1.0 Newsgroups: aus.computers.java,comp.lang.java,comp.lang.java.programmer