• Post Reply Bookmark Topic Watch Topic
  • New Topic

Determine a Servlet's name at runtime  RSS feed

 
Freddy Villalba
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everybody,
How can I determine the name of a servlet (i.e. the name specified for it by the corresponding <servlet-name> tag inside the web.xml descriptor file)?
Assume you know the fully-qualified classname of the Servlet you are interested in.
I believe (not 100% sure) this was possible in previous Servlet APIs - at least 'till v2.1 - but I'm not sure it is anymore.
Thanks in advance,
Freddy.
 
Bosun Bello
Ranch Hand
Posts: 1512
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use request.getRequestURI().
[ February 11, 2004: Message edited by: Bosun Bello ]
 
danny liu
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
User ServletConfig.getServletName method
dan
 
Freddy Villalba
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by danny liu:
User ServletConfig.getServletName method
dan

Thanx for your answers. I agree with you, but I've realized I should have been a little bit more specific. I apologize (to you all).
This is what I want to do: it's a method in a Factory class that, based on a few parameters, builds the URL to access (forward / redirect) a given Servlet (always the same servlet). However, I want it to be "web.xml-independent". That is, that the URL can be built without having to "know" the name assigned to that Servlet inside the web.xml DF.
In order to do what you say, I must be able to access the instance of the servlet that is already in use. Creating a new instance "by hand" (i.e. "new XXXServlet()") and then trying to get ServletConfig out of it will not work since it will be null.
Then, my question should have been as follows:
From a normal class, and being able to access the request (/ session / servlet context): how can I recover (based on the fully-qualified classname) the instance of a Servlet - already present in memory - being managed by the Servlet container, in order to determine its Servlet Name (for that servlet context)?
OR EVEN MORE SIMPLE: given Servlets A and B, how can I obtain A's servlet-name (as specified inside web.xml) from servlet B (at runtime)?
Thanx in advance (again),
Freddy.
[ February 12, 2004: Message edited by: Freddy Villalba ]
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!