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:
@@ -464,9 +464,14 @@ public abstract class WebMvcConfigurationSupport implements ApplicationContextAw
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a {@link HandlerExceptionResolverComposite} that contains a list
|
||||
* of exception resolvers. To customize the list of exception resolvers,
|
||||
* consider overriding {@link #configureHandlerExceptionResolvers(List)}.
|
||||
* Returns a {@link HandlerExceptionResolverComposite} containing a list
|
||||
* of exception resolvers obtained either through
|
||||
* {@link #configureHandlerExceptionResolvers(List)} or through
|
||||
* {@link #addDefaultHandlerExceptionResolvers(List)}.
|
||||
* <p><strong>Note:</strong> This method cannot be made final due to CGLib
|
||||
* constraints. Rather than overriding it, consider overriding
|
||||
* {@link #configureHandlerExceptionResolvers(List)}, which allows
|
||||
* providing a list of resolvers.
|
||||
*/
|
||||
@Bean
|
||||
public HandlerExceptionResolver handlerExceptionResolver() throws Exception {
|
||||
|
||||
@@ -417,6 +417,21 @@ public class RequestContext {
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the path to URL mappings within the current servlet including the
|
||||
* context path and the servlet path of the original request. This is useful
|
||||
* for building links to other resources within the application where a
|
||||
* servlet mapping of the style {@code "/main/*"} is used.
|
||||
* <p>Delegates to the UrlPathHelper for decoding the context path.
|
||||
* @see javax.servlet.http.HttpServletRequest#getContextPath
|
||||
* @see javax.servlet.http.HttpServletRequest#getServletPath()
|
||||
* @see #getUrlPathHelper
|
||||
*/
|
||||
public String getPathToServlet() {
|
||||
return this.urlPathHelper.getOriginatingContextPath(this.request)
|
||||
+ this.urlPathHelper.getOriginatingServletPath(this.request);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the request URI of the original request, that is, the invoked URL without parameters. This is particularly
|
||||
* useful as HTML form action target, possibly in combination with the original query string. <p><b>Note this
|
||||
|
||||
Reference in New Issue
Block a user