Servlets { public static String getRequestPathFromUri(String url) { return getRequestPathFromUri(url, ""); } protected  Servlets(); static ServletResource getResource(ServletContext sc,String path); static ServletResource getResource(ServletContext sc,String path, Locale locale); @SuppressWarnings("unchecked") static Map<String,String> getInitParamsMap(FilterConfig config); @SuppressWarnings("unchecked") static Map<String, String> getInitParamsMap(ServletConfig config); @SuppressWarnings("unchecked") static Map<String, String> getInitParamsMap(ServletContext sc); static String getRealPath(ServletContext servletContext, String path); static String getRequestUriWithQueryString(HttpServletRequest request); static String getRequestPathFromUri(String url); static String getRequestPathFromUri(String url, String contextPath); static boolean isIncludeRequest(ServletRequest request); static File getTempDir(ServletContext servletContext); static String getMimeType(ServletContext sc,String filename); static final String INCLUDE_REQUEST_URI_ATTRIBUTE; static final String INCLUDE_CONTEXT_PATH_ATTRIBUTE; static final String INCLUDE_SERVLET_PATH_ATTRIBUTE; static final String INCLUDE_PATH_INFO_ATTRIBUTE; static final String INCLUDE_QUERY_STRING_ATTRIBUTE; static final String FORWARD_REQUEST_URI_ATTRIBUTE; static final String FORWARD_CONTEXT_PATH_ATTRIBUTE; static final String FORWARD_SERVLET_PATH_ATTRIBUTE; static final String FORWARD_PATH_INFO_ATTRIBUTE; static final String FORWARD_QUERY_STRING_ATTRIBUTE; static final String ERROR_STATUS_CODE_ATTRIBUTE; static final String ERROR_EXCEPTION_TYPE_ATTRIBUTE; static final String ERROR_MESSAGE_ATTRIBUTE; static final String ERROR_EXCEPTION_ATTRIBUTE; static final String ERROR_REQUEST_URI_ATTRIBUTE; static final String ERROR_SERVLET_NAME_ATTRIBUTE; static final String TEMP_DIR_CONTEXT_ATTRIBUTE; }
@Test public void testGetRequestPathFromUrl() { String url = "http: assertEquals("/context/path1", Servlets.getRequestPathFromUri(url, "")); assertEquals("/path1", Servlets.getRequestPathFromUri(url, "/context")); url = "http: assertEquals("/context/path1", Servlets.getRequestPathFromUri(url, "")); assertEquals("/path1", Servlets.getRequestPathFromUri(url, "/context")); url = "/context/path1?p=1"; assertEquals("/context/path1", Servlets.getRequestPathFromUri(url, "")); assertEquals("/path1", Servlets.getRequestPathFromUri(url, "/context")); }