SPR-8863 Add RequestContext.getPathToServlet() method.

This method allows a view to access the combined context path and
servlet mapping path for prefixing URLs without having to specify
the literal part of a servlet mapping such as "/main/*") 
explicitly everywhere. For example:

${requestContext.pathToServlet}/css/main.css
This commit is contained in:
Rossen Stoyanchev
2011-12-01 22:56:51 +00:00
parent 0ef3beb462
commit 9f98f77c3e
4 changed files with 64 additions and 7 deletions

View File

@@ -280,6 +280,20 @@ public class UrlPathHelper {
return decodeRequestString(request, contextPath);
}
/**
* Return the servlet path for the given request, detecting an include request
* URL if called within a RequestDispatcher include.
* @param request current HTTP request
* @return the servlet path
*/
public String getOriginatingServletPath(HttpServletRequest request) {
String servletPath = (String) request.getAttribute(WebUtils.FORWARD_SERVLET_PATH_ATTRIBUTE);
if (servletPath == null) {
servletPath = request.getServletPath();
}
return servletPath;
}
/**
* Return the query string part of the given request's URL. If this is a forwarded request,
* correctly resolves to the query string of the original request.