tags:

views:

38

answers:

1

Let's say I have this in my web.xml:


<servlet>
    <description></description>
    <display-name>MainServ</display-name>
    <servlet-name>MainServ</servlet-name>
    <servlet-class>MainServ</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>MainServ</servlet-name>
    <url-pattern>/MainServ</url-pattern>
</servlet-mapping>

Imagine I'm in that servlet's doGet method. Is there anyway of getting at the /MainServ value?

+3  A: 

Via HttpServletRequest.getServletPath; from the Javadoc:

This path starts with a "/" character and includes either the servlet name or a path to the servlet, but does not include any extra path information or a query string.

E.g.:

String path = req.getServletPath();

...if you've called the first argument to doGet req.

T.J. Crowder
Thanks. Exactly what I needed.
Geo