tags:

views:

41

answers:

2

If I've something like this:

<servlet>
    <display-name>Step</display-name>
    <servlet-name>Step</servlet-name>
    <servlet-class>com.foo.AServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>Step</servlet-name>
    <url-pattern>/aservlet/*</url-pattern>
</servlet-mapping>

and the servlet is invoked by a request of the form /aservlet/ABC

then is there a way to get the value "ABC" in the code? i.e inside the doGet() or doPost() methods of the class AServlet?

+1  A: 
public void doGet(HttpServletRequest request, HttpServletResponse response){
    String uriRequest = request.getRequestURI();
    //parse to obtain only the last part
    String uriRequest = uriRequest.substring(uriRequest.lastIndexOf("/")+1);
}

Same thing for doPost().

Cesar
+3  A: 

THe easiest thing to do is,

   String path = request.getPathInfo();

Which returns "/ABC".

ZZ Coder