public class ServletUtil extends Object
| Constructor and Description |
|---|
ServletUtil() |
| Modifier and Type | Method and Description |
|---|---|
static String |
getBaseURL(javax.servlet.http.HttpServletRequest request)
取得request请求的基准URL。
|
static String |
getResourcePath(javax.servlet.http.HttpServletRequest request)
取得request所请求的资源路径。
|
static String |
getServletBaseURL(javax.servlet.http.HttpServletRequest request)
取得request请求的基准URL。
对于前缀匹配的servlet,等同于
SERVER/contextPath/servletPath。例如映射
/turbine/*:http://localhost/myapp/turbine/xx/yy
的baseURL为 http://localhost/myapp/turbine。
对于后缀匹配的servlet,等同于SERVER/contextPath。例如映射
*.do:http://localhost/myapp/xx/yy.do的baseURL为
http://localhost/myapp。
|
static String |
getServletResourcePath(javax.servlet.http.HttpServletRequest request)
取得request所请求的资源路径。
对于前缀匹配的servlet,等同于
getPathInfo()。例如映射
/turbine/*:/turbine/xx/yy的resource path为
/xx/yy。
对于后缀匹配的servlet,等同于 getServletPath()。例如映射
*.do:/xx/yy.do的resource path为
/xx/yy.do。
|
static boolean |
isPrefixServletMapping(javax.servlet.http.HttpServletRequest request)
判断servlet是否为前缀映射。
|
static String |
normalizeURI(String uri)
规格化URI。
|
static boolean |
startsWithPath(String path,
String fullpath)
判断path是否为fullpath的前缀,匹配到“/”边界。
startsWithPath("/index", "/index.htm") == false。
startsWithPath("/path", "/path/index") == true。
|
public static boolean isPrefixServletMapping(javax.servlet.http.HttpServletRequest request)
Servlet mapping有两种匹配方式:前缀匹配和后缀匹配。
public static String getResourcePath(javax.servlet.http.HttpServletRequest request)
资源路径为getServletPath() + getPathInfo()。
注意,ResourcePath以"/"开始,如果无内容,则返回空字符串
""。
public static String getBaseURL(javax.servlet.http.HttpServletRequest request)
基准URL等同于SERVER/contextPath。
基准URL总是不以"/"结尾。
以下等式总是成立:fullURL = baseURL + resourcePath。
public static String getServletResourcePath(javax.servlet.http.HttpServletRequest request)
getPathInfo()。例如映射
/turbine/*:/turbine/xx/yy的resource path为
/xx/yy。getServletPath()。例如映射
*.do:/xx/yy.do的resource path为
/xx/yy.do。
注意,ResourcePath以"/"开始,如果无内容,则返回空字符串
""。
本方法适用于servlet-mapping对应的URL。
public static String getServletBaseURL(javax.servlet.http.HttpServletRequest request)
SERVER/contextPath/servletPath。例如映射
/turbine/*:http://localhost/myapp/turbine/xx/yy
的baseURL为 http://localhost/myapp/turbine。SERVER/contextPath。例如映射
*.do:http://localhost/myapp/xx/yy.do的baseURL为
http://localhost/myapp。
基准URL总是不以"/"结尾。
以下等式总是成立:fullURL = servletBaseURL + servletResourcePath。
本方法适用于servlet-mapping对应的URL。
Copyright © 2006–2018 TinyGroup. All rights reserved.