public static String normalizeRequestUri(HttpServletRequest httpRequest){
  String retVal=httpRequest.getRequestURI();
  String contextPath=httpRequest.getContextPath();
  if (retVal.startsWith(contextPath)) {
    retVal=retVal.substring(contextPath.length());
  }
  String servletPath=httpRequest.getServletPath();
  if (retVal.startsWith(servletPath)) {
    retVal=retVal.substring(servletPath.length());
  }
  return retVal;
}

public static String normalizeRequestUri ( HttpServletRequest httpRequest ) { String retVal = httpRequest . getRequestURI ( ) ; String contextPath = httpRequest . getContextPath ( ) ; if ( retVal . startsWith ( contextPath ) ) { retVal = retVal . substring ( contextPath . length ( ) ) ; } String servletPath = httpRequest . getServletPath ( ) ; if ( retVal . startsWith ( servletPath ) ) { retVal = retVal . substring ( servletPath . length ( ) ) ; } return retVal ; }
returns the part of the path we are interested in when doing pattern matching . this should work whether or not the servlet or filter is explicitly mapped inside of the web . xml since it always strips off the contextpath .
