String servletPath = getServletPath(request); String sanitizedPathWithinApp = getSanitizedPath(pathWithinApp); String path;
String servletPath = getServletPath(request); String sanitizedPathWithinApp = getSanitizedPath(pathWithinApp); String path;
/** * Returns the servlet-mapping prefix for the given request or an empty * String if the servlet is mapped by a suffix. */ public static String getServletPrefix(HttpServletRequest request) { String path = urlPathHelper.getPathWithinApplication(request); String servletPath = urlPathHelper.getServletPath(request); if (path.length() > servletPath.length() || (path.equals(servletPath) && path.indexOf('.') == -1)) { return servletPath; } return ""; }
/** * Returns the servlet-mapping suffix for the given request or an empty * String if the servlet is mapped by a prefix. */ public static String getServletSuffix(HttpServletRequest request) { String path = urlPathHelper.getPathWithinApplication(request); if (path.equals(urlPathHelper.getServletPath(request))) { int dotIndex = path.lastIndexOf('.'); if (dotIndex >= 0 && dotIndex > path.lastIndexOf('/')) { return path.substring(dotIndex); } } return ""; }
/** * Return the path within the servlet mapping for the given request, * i.e. the part of the request's URL beyond the part that called the servlet, * or "" if the whole URL has been used to identify the servlet. * <p>Regards include request URL if called within a RequestDispatcher include. * <p>E.g.: servlet mapping = "/test/*"; request URI = "/test/a" -> "/a". * <p>E.g.: servlet mapping = "/test"; request URI = "/test" -> "". * <p>E.g.: servlet mapping = "/*.test"; request URI = "/a.test" -> "". * @param request current HTTP request * @return the path within the servlet mapping, or "" */ public String getPathWithinServletMapping(HttpServletRequest request) { String pathWithinApp = getPathWithinApplication(request); String servletPath = getServletPath(request); if (pathWithinApp.startsWith(servletPath)) { // Normal case: URI contains servlet path. return pathWithinApp.substring(servletPath.length()); } else { // Special case: URI is different from servlet path. // Can happen e.g. with index page: URI="/", servletPath="/index.html" // Use servlet path in this case, as it indicates the actual target path. return servletPath; } }
/** * Inspect the handler mapping at the level of HTTP {@link RequestMethod}. * Each URI pattern that is mapped can be mapped to multiple request * methods. If the mapping is not explicit this method only returns GET * (even though technically it would respond to POST as well). * * @param request the current servlet request (used to extract a page * attribute "sevletPath") * @param model {@link org.springframework.ui.ModelMap} to be used * * @return a map of URI pattern to request methods accepted */ @RequestMapping(value = { "/", "/home" }, method = RequestMethod.GET) public String getResources(HttpServletRequest request, ModelMap model) { String servletPath = this.servletPath; if (servletPath == null) { servletPath = new UrlPathHelper().getServletPath(request); } model.addAttribute("servletPath", servletPath); List<ResourceInfo> resources = new ArrayList<ResourceInfo>(); if (!request.getRequestURI().endsWith(".json")) { resources.addAll(defaultResources); } resources.addAll(jsonResources); model.addAttribute("resources", resources); return "home"; }
/** * Inspect the handler mapping at the level of HTTP {@link RequestMethod}. * Each URI pattern that is mapped can be mapped to multiple request * methods. If the mapping is not explicit this method only returns GET * (even though technically it would respond to POST as well). * * @param request the current servlet request (used to extract a page * attribute "sevletPath") * @param model {@link org.springframework.ui.ModelMap} to be used * * @return a map of URI pattern to request methods accepted */ @RequestMapping(value = { "/home" }, method = RequestMethod.GET) public String getResources(HttpServletRequest request, ModelMap model) { String servletPath = this.servletPath; if (servletPath == null) { servletPath = new UrlPathHelper().getServletPath(request); } model.addAttribute("servletPath", servletPath); List<ResourceInfo> resources = new ArrayList<ResourceInfo>(); if (!request.getRequestURI().endsWith(".json")) { resources.addAll(defaultResources); } resources.addAll(jsonResources); model.addAttribute("resources", resources); return "home"; }
String servletPath = getServletPath(request); String sanitizedPathWithinApp = getSanitizedPath(pathWithinApp); String path;
String servletPath = getServletPath(request); String sanitizedPathWithinApp = getSanitizedPath(pathWithinApp); String path;