| Modifier and Type | Class and Description |
|---|---|
static interface |
Encodes.URLEncoder
The URL encoder used to encode URL by including the session ID,
and servlet context path.
|
| Modifier | Constructor and Description |
|---|---|
protected |
Encodes() |
| Modifier and Type | Method and Description |
|---|---|
static StringBuffer |
addToQueryString(StringBuffer sb,
Map params)
/** Appends a map of parameters (name=value) to a query string.
|
static StringBuffer |
addToQueryString(StringBuffer sb,
String name,
Object value)
Appends a parameter (name=value) to a query string.
|
static boolean |
containsQuery(String str,
String name)
Tests whether a parameter exists in the query string.
|
static String |
encodeURI(String s)
Does the HTTP encoding for the URI location.
|
static String |
encodeURIComponent(String s)
Does the HTTP encoding for an URI query parameter.
|
static String |
encodeURL(javax.servlet.ServletContext ctx,
javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
String uri)
Encodes an URL.
|
static StringBuffer |
removeFromQueryString(StringBuffer sb,
String name)
Remove all name/value pairs of the specified name from a string.
|
static String |
removeFromQueryString(String str,
String name)
Remove all name/value pairs of the specified name from a string.
|
static StringBuffer |
setToQueryString(StringBuffer sb,
Map params)
Sets a map of parameters (name=value) to a query string.
|
static StringBuffer |
setToQueryString(StringBuffer sb,
String name,
Object value)
Sets the parameter (name=value) to a query string.
|
static String |
setToQueryString(String str,
Map params)
Sets a map of parameters (name=value) to a query string.
|
static String |
setToQueryString(String str,
String name,
Object value)
Sets the parameter (name=value) to a query string.
|
public static final String encodeURI(String s) throws UnsupportedEncodingException
Since encodeURL(ServletContext, ServletRequest, ServletResponse, String)
will invoke this method automatically, you rarely need this method.
s - the string to encode; null is OKUnsupportedEncodingExceptionencodeURIComponent(java.lang.String)public static final String encodeURIComponent(String s) throws UnsupportedEncodingException
encodeURIComponent(name) + '=' + encodeURIComponent(value).
Since encodeURL(ServletContext, ServletRequest, ServletResponse, String)
will not invoke this method automatically, you'd better
to encode each query parameter by this method or
addToQueryString(StringBuffer,Map).
s - the string to encode; null is OKUnsupportedEncodingExceptionaddToQueryString(StringBuffer,String,Object),
encodeURI(java.lang.String)public static final StringBuffer addToQueryString(StringBuffer sb, Map params) throws UnsupportedEncodingException
request.getRequestDispatcher(
addToQueryStirng(new StringBuffer(uri), params).toString());
Since RequestDispatcher.include and forward do not allow wrapping the request and response -- see spec and the implementation of both Jetty and Catalina, we have to use this method to pass the parameters.
params - a map of parameters; format: (String, Object) or
(String, Object[]); null is OKUnsupportedEncodingExceptionpublic static final StringBuffer addToQueryString(StringBuffer sb, String name, Object value) throws UnsupportedEncodingException
The query string might contain servlet path and other parts. This method starts the searching from the first '?'. If the query string doesn't contain '?', it is assumed to be a string without query's name/value pairs.
value - the value. If it is null, only name is appended.
If it is an array of objects, multiple pairs of name=value[j] will
be appended.UnsupportedEncodingExceptionpublic static final String setToQueryString(String str, String name, Object value) throws UnsupportedEncodingException
The query string might contain servlet path and other parts. This method starts the searching from the first '?'. If the query string doesn't contain '?', it is assumed to be a string without query's name/value pairs.
str - The query string like xxx?xxx=xxx&xxx=xxx or null.name - The get parameter name.value - The value associated with the get parameter name.UnsupportedEncodingExceptionaddToQueryString(java.lang.StringBuffer, java.util.Map)public static final StringBuffer setToQueryString(StringBuffer sb, String name, Object value) throws UnsupportedEncodingException
public static final String setToQueryString(String str, Map params) throws UnsupportedEncodingException
public static final StringBuffer setToQueryString(StringBuffer sb, Map params) throws UnsupportedEncodingException
public static final boolean containsQuery(String str, String name)
public static final String removeFromQueryString(String str, String name) throws UnsupportedEncodingException
The query string might contain servlet path and other parts. This method starts the searching from the last '?'. If the query string doesn't contain '?', it is assumed to be a string without query's name/value pairs.
public static final StringBuffer removeFromQueryString(StringBuffer sb, String name) throws UnsupportedEncodingException
public static final String encodeURL(javax.servlet.ServletContext ctx, javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, String uri) throws javax.servlet.ServletException
Servlets.locate(ServletContext, ServletRequest, String, Locator)
for details.
In additions, if uri starts with "/", the context path, e.g., /zkdemo, is prefixed. In other words, "/ab/cd" means it is relevant to the servlet context path (say, "/zkdemo").
If uri starts with "~abc/", it means it is relevant to a foreign Web context called /abc. And, it will be converted to "/abc/" first (without prefix request.getContextPath()).
Finally, the uri is encoded by HttpServletResponse.encodeURL.
This method invokes encodeURI(java.lang.String) for any characters
before '?'. However, it does NOT encode any character after '?'. Thus,
you might have to invoke
encodeURIComponent(java.lang.String) or addToQueryString(StringBuffer,Map)
to encode the query parameters.
In a sophisticated environment, e.g.,
Reverse Proxy,
the encoded URL might have to be prefixed with some special prefix.
To do that, you can implement Encodes.URLEncoder, and then
specify the class with the library property called
org.zkoss.web.servlet.http.URLEncoder.
When encodeURL(javax.servlet.ServletContext, javax.servlet.ServletRequest, javax.servlet.ServletResponse, java.lang.String) encodes an URL, it will invoke
Encodes.URLEncoder.encodeURL(javax.servlet.ServletContext, javax.servlet.ServletRequest, javax.servlet.ServletResponse, java.lang.String, org.zkoss.web.servlet.http.Encodes.URLEncoder) such you can do customized encoding,
such as insert a special prefix.
request - the request; never nullresponse - the response; never nulluri - it must be null, empty or starts with "/". It might contain
"*" for current browser code and Locale.ctx - the servlet context; used only if "*" is contained in uriIndexOutOfBoundException - if uri is emptyjavax.servlet.ServletExceptionServlets.locate(javax.servlet.ServletContext, javax.servlet.ServletRequest, java.lang.String, org.zkoss.util.resource.Locator),
Servlets.generateURI(java.lang.String, java.util.Map, int)Copyright © 2021. All rights reserved.