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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user