File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes How to get the url-pattern of a servlet ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to get the url-pattern of a servlet ?" Watch "How to get the url-pattern of a servlet ?" New topic

How to get the url-pattern of a servlet ?

qzlmk lmklq

Joined: Mar 22, 2006
Posts: 1
Hi all,

I have defined a servlet-mapping in the web.xml of my webapp:

I want to retrieve the url-pattern of a specific servlet from another one.

For instance, from a method of my_servlet I want to obtain the url-pattern corresponding to my_servlet_bis

I try to use the ServletContext but I don't find a way to do this...

Any idea ?
[ March 22, 2006: Message edited by: qzlmk lmklq ]
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63866

"qzlmk lmklq",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

JavaRanch Sheriff

[Asking smart questions] [About Bear] [Books by Bear]
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

A servlet can have zero, one, or many url-patterns mapped to it.
There are methods in HttpServletRequest for finding out which URL was used for each particular request but the servlet itself has no way of knowing which URL patterns have been mapped to it.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: How to get the url-pattern of a servlet ?
It's not a secret anymore!