The Method request.getRequestURI() returns URI with context path.
For example, if the base URL of an application is http://localhost:8080/myapp/ (i.e.
http://localhost:8080/myapp/
A way to do this is to rest the servelet context path from request URI.
String p = request.getRequestURI(); String cp = getServletContext().getContextPath(); if (p.startsWith(cp)) { String.err.println(p.substring(cp.length()); }
Read here .