public class WebUtils extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
DEFAULT_CHARACTER_ENCODING
Default character encoding to use when
request.getCharacterEncoding
returns null, according to the Servlet spec. |
static String |
FORWARD_CONTEXT_PATH_ATTRIBUTE |
static String |
FORWARD_PATH_INFO_ATTRIBUTE |
static String |
FORWARD_QUERY_STRING_ATTRIBUTE |
static String |
FORWARD_REQUEST_URI_ATTRIBUTE
Standard Servlet 2.4+ spec request attributes for forward URI and paths.
|
static String |
FORWARD_SERVLET_PATH_ATTRIBUTE |
static String |
INCLUDE_CONTEXT_PATH_ATTRIBUTE |
static String |
INCLUDE_PATH_INFO_ATTRIBUTE |
static String |
INCLUDE_QUERY_STRING_ATTRIBUTE |
static String |
INCLUDE_REQUEST_URI_ATTRIBUTE |
static String |
INCLUDE_SERVLET_PATH_ATTRIBUTE |
| 构造器和说明 |
|---|
WebUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static String |
decodeRequestString(javax.servlet.http.HttpServletRequest request,
String source)
Decode the given source string with a URLDecoder.
|
protected static String |
determineEncoding(javax.servlet.http.HttpServletRequest request)
Determine the encoding for the given request.
|
static String |
getCleanParam(javax.servlet.ServletRequest request,
String paramName)
Convenience method that returns a request parameter value, first running it through
|
static String |
getContextPath(javax.servlet.http.HttpServletRequest request)
Return the context path for the given request, detecting an include request
URL if called within a RequestDispatcher include.
|
static String |
getPathWithinApplication(javax.servlet.http.HttpServletRequest request)
Return the path within the web application for the given request.
|
static String |
getRequestUri(javax.servlet.http.HttpServletRequest request)
Return the request URI for the given request, detecting an include request
URL if called within a RequestDispatcher include.
|
static String |
normalize(String path)
Normalize a relative URI path that may have relative values ("/./",
"/../", and so on ) it it.
|
static String |
removeParam(String queryString,
String name) |
static javax.servlet.http.HttpServletRequest |
toHttp(javax.servlet.ServletRequest request)
A convenience method that merely casts the incoming
ServletRequest to an
HttpServletRequest:
return (HttpServletRequest)request;
Logic could be changed in the future for logging or throwing an meaningful exception in
non HTTP request environments (e.g. |
static javax.servlet.http.HttpServletResponse |
toHttp(javax.servlet.ServletResponse response)
A convenience method that merely casts the incoming
ServletResponse to an
HttpServletResponse:
return (HttpServletResponse)response;
Logic could be changed in the future for logging or throwing an meaningful exception in
non HTTP request environments (e.g. |
public static final String INCLUDE_CONTEXT_PATH_ATTRIBUTE
public static final String INCLUDE_SERVLET_PATH_ATTRIBUTE
public static final String INCLUDE_QUERY_STRING_ATTRIBUTE
public static final String FORWARD_REQUEST_URI_ATTRIBUTE
If forwarded to via a RequestDispatcher, the current resource will see its own URI and paths. The originating URI and paths are exposed as request attributes.
public static final String FORWARD_CONTEXT_PATH_ATTRIBUTE
public static final String FORWARD_SERVLET_PATH_ATTRIBUTE
public static final String FORWARD_QUERY_STRING_ATTRIBUTE
public static String getPathWithinApplication(javax.servlet.http.HttpServletRequest request)
http://www.somehost.com/myapp/my/url.jsp,
for an application deployed to /mayapp (the application's context path), this method would return
/my/url.jsp.request - current HTTP requestpublic static String getRequestUri(javax.servlet.http.HttpServletRequest request)
As the value returned by request.getRequestURI() is not
decoded by the servlet container, this method will decode it.
The URI that the web container resolves should be correct, but some containers like JBoss/Jetty incorrectly include ";" strings like ";jsessionid" in the URI. This method cuts off such incorrect appendices.
request - current HTTP requestpublic static String normalize(String path)
path - Relative path to be normalizedpublic static String getContextPath(javax.servlet.http.HttpServletRequest request)
As the value returned by request.getContextPath() is not
decoded by the servlet container, this method will decode it.
request - current HTTP requestpublic static String decodeRequestString(javax.servlet.http.HttpServletRequest request, String source)
The default implementation uses URLDecoder.decode(input, enc).
request - current HTTP requestsource - the String to decodeDEFAULT_CHARACTER_ENCODING,
ServletRequest.getCharacterEncoding(),
URLDecoder.decode(String, String),
URLDecoder.decode(String)protected static String determineEncoding(javax.servlet.http.HttpServletRequest request)
The default implementation checks the request's
character encoding, and if that
null, falls back to the DEFAULT_CHARACTER_ENCODING.
request - current HTTP requestnull)ServletRequest.getCharacterEncoding()public static javax.servlet.http.HttpServletRequest toHttp(javax.servlet.ServletRequest request)
ServletRequest to an
HttpServletRequest:
return (HttpServletRequest)request;
Logic could be changed in the future for logging or throwing an meaningful exception in
non HTTP request environments (e.g. Portlet API).request - the incoming ServletRequestrequest argument casted to an HttpServletRequest.public static javax.servlet.http.HttpServletResponse toHttp(javax.servlet.ServletResponse response)
ServletResponse to an
HttpServletResponse:
return (HttpServletResponse)response;
Logic could be changed in the future for logging or throwing an meaningful exception in
non HTTP request environments (e.g. Portlet API).response - the outgoing ServletResponseresponse argument casted to an HttpServletResponse.public static String getCleanParam(javax.servlet.ServletRequest request, String paramName)
request - the servlet request.paramName - the parameter name.Copyright © 2019. All rights reserved.