一. UrlPathHelper
/** * 用于URL路径匹配的帮助类。提供了对于URL路径的支持,在RequestDispatcher includes和支持URL解码方面 * * <p>Used by {@link org.springframework.web.servlet.handler.AbstractUrlHandlerMapping} * and {@link org.springframework.web.servlet.support.RequestContext} for path matching * and/or URI determination. * */ public class UrlPathHelper { /** * 特殊的服务器请求属性,表明原始的请求uri * 优于标准的Servlet2.4服务端的转发属性,因为我们需要恰好是请求转发链中的第一个uri */ private static final String WEBSPHERE_URI_ATTRIBUTE = "com.ibm.websphere.servlet.uri_non_decoded"; private static final Log logger = LogFactory.getLog(UrlPathHelper.class); @Nullable static volatile Boolean websphereComplianceFlag; private boolean alwaysUseFullPath = false; private boolean urlDecode = true; private boolean removeSemicolonContent = true; /** iso-8859-1 */ private String defaultEncoding = WebUtils.DEFAULT_CHARACTER_ENCODING; /** * URL查找是否应当总是使用全路径,在当前的web application context范围内 * {@link javax.servlet.ServletContext#getContextPath()}. * <p>If set to {@literal false} the path within the current servlet mapping * is used instead if applicable (i.e. in the case of a prefix based Servlet * mapping such as "/myServlet/*"). * <p>By default this is set to "false". */ public void setAlwaysUseFullPath(boolean alwaysUseFullPath) { this.alwaysUseFullPath = alwaysUseFullPath; } /** * 上下文路径和请求URI是否应当被解码 */ public void setUrlDecode(boolean urlDecode) { this.urlDecode = urlDecode; } /** * 当查找lookup path时,是否解码请求URI */ public boolean isUrlDecode() { return this.urlDecode; } /** * 请求URI中,是否删除;后的部分 */ public void setRemoveSemicolonContent(boolean removeSemicolonContent) { this.removeSemicolonContent = removeSemicolonContent; } /** * 是否应当删除;后的部分 */ public boolean shouldRemoveSemicolonContent() { return this.removeSemicolonContent; } /** * Set the default character encoding to use for URL decoding. * Default is ISO-8859-1 */ public void setDefaultEncoding(String defaultEncoding) { this.defaultEncoding = defaultEncoding; } /** * Return the default character encoding to use for URL decoding. */ protected String getDefaultEncoding() { return this.defaultEncoding; } /** * Return the mapping lookup path for the given request, within the current * servlet mapping if applicable, else within the web application. */ public String getLookupPathForRequest(HttpServletRequest request) { // Always use full path within current servlet context? if (this.alwaysUseFullPath) { return getPathWithinApplication(request); } // Else, use path within current servlet mapping if applicable String rest = getPathWithinServletMapping(request); if (!"".equals(rest)) { return rest; } else { return getPathWithinApplication(request); } } /** * Variant of {@link #getLookupPathForRequest(HttpServletRequest)} that * automates checking for a previously computed lookupPath saved as a */ public String getLookupPathForRequest(HttpServletRequest request, @Nullable String
Spring MVC源码解析 - UrlPathHelper
最新推荐文章于 2024-10-07 15:58:21 发布