| java.lang.Object org.zkoss.web.servlet.Servlets
All known Subclasses: org.zkoss.web.servlet.http.Https,
Field Summary | |
final public static int | APPEND_PARAM Whether to append params if both uri and params contain the same
parameter. | final public static int | IGNORE_PARAM Whether to ignore params if both uri and params contain the same
parameter. | final public static int | OVERWRITE_URI Whether to overwrite uri if both uri and params contain the same
parameter. | final public static int | PASS_THRU_ATTR Whether the specified parameters shall be passed thru the request
attribute called arg. |
Constructor Summary | |
protected | Servlets() Utilities; no instantiation required. |
Method Summary | |
final public static ExtendletContext | addExtendletContext(ServletContext ctx, String name, ExtendletContext extctx) Adds an extended context. | final public static void | forward(ServletContext ctx, ServletRequest request, ServletResponse response, String uri, Map params, int mode) Forward to the specified URI.
It enhances RequestDispatcher in the following ways.
- It handles "~ctx"" where ctx is the context path of the
foreign context.
| final public static void | forward(ServletContext ctx, ServletRequest request, ServletResponse response, String uri) A shortcut of forward(request, response, uri, null, 0). | final public static String | generateURI(String uri, Map params, int mode) Generates URI by appending the parameters. | final public static List | getContextPaths() Returns a list of context paths (e.g., "/abc") that this application
has. | final public static ExtendletContext | getExtendletContext(ServletContext ctx, String name) Returns the extended context of the specified name. | final public static String | getExtension(String path) Returns the file extension of the specified path, or null
if no extension at all.
Note: the extension is converted to the lower case.
Note: it assumes the session ID, if any, starts with semicolon.
For example, the path could be "/a/b.zul;jsession=xxx".
Parameters: path - the path. | final public static String | getLimitTimeOffer() Returns a token to represent a limit-time offer. | final public static RequestDispatcher | getRequestDispatcher(ServletContext ctx, ServletRequest request, String uri, Map params, int mode) Returns the request dispatch of the specified URI.
Parameters: ctx - the servlet context. | final public static URL | getResource(ServletContext ctx, String uri) Returns the resource of the specified uri. | final public static InputStream | getResourceAsStream(ServletContext ctx, String uri) Returns the resource stream of the specified uri. | final public static String | getUserAgent(ServletRequest req) Returns the user-agent header, which indicates what the client is,
or an empty string if not available. | final public static void | include(ServletContext ctx, ServletRequest request, ServletResponse response, String uri, Map params, int mode) Includes the resource at the specified URI.
It enhances RequestDispatcher to allow the inclusion with
a parameter map -- acutually converting parameters to a query string
and appending it to uri.
NOTE: don't include query parameters in uri.
Parameters: ctx - the servlet context. | final public static void | include(ServletContext ctx, ServletRequest request, ServletResponse response, String uri) A shortcut of include(request, response, uri, null, 0). | final public static boolean | isExplorer(ServletRequest req) Returns whether the browser is Internet Explorer. | final public static boolean | isExplorer7(ServletRequest req) Returns whether the browser is Explorer 7 or later. | final public static boolean | isForwarded(ServletRequest request) Tests whether this page is forwarded by another page. | final public static boolean | isGecko(ServletRequest req) | final public static boolean | isHilDevice(ServletRequest req) Returns whether the client is a mobile device supporting HIL
(Handset Interactive Language). | final public static boolean | isIncluded(ServletRequest request) Tests whether this page is included by another page. | final public static boolean | isMilDevice(ServletRequest req) Returns whether the client is a mobile device supporting MIL
(Mobile Interactive Language). | final public static boolean | isOfferExpired(String lto, int timeout) Returns whether a token returned by getLimitTimeOffer expired. | final public static boolean | isOpera(ServletRequest req) Returns whether the browser is Opera. | final public static boolean | isRobot(ServletRequest req) Returns whether the client is a robot (such as Web crawlers). | final public static boolean | isSafari(ServletRequest req) Returns whether the browser is Safari. | final public static boolean | isServlet23() Returns whether the current Web server supports Servlet 2.3 or above. | final public static boolean | isServlet24() Returns whether the current Web server supports Servlet 2.4 or above. | final public static boolean | isUniversalURL(String uri) | final public static String | locate(ServletContext ctx, ServletRequest request, String pgpath, Locator locator) Locates a page based on the specified Locale. | final public static ExtendletContext | removeExtendletContext(ServletContext ctx, String name) Removes an extended context of the specified name. |
APPEND_PARAM | final public static int APPEND_PARAM(Code) | | Whether to append params if both uri and params contain the same
parameter. In other words, they both appear as the final query string.
Used by
Servlets.generateURI |
IGNORE_PARAM | final public static int IGNORE_PARAM(Code) | | Whether to ignore params if both uri and params contain the same
parameter.
Used by
Servlets.generateURI |
OVERWRITE_URI | final public static int OVERWRITE_URI(Code) | | Whether to overwrite uri if both uri and params contain the same
parameter.
Used by
Servlets.generateURI |
PASS_THRU_ATTR | final public static int PASS_THRU_ATTR(Code) | | Whether the specified parameters shall be passed thru the request
attribute called arg.
|
Servlets | protected Servlets()(Code) | | Utilities; no instantiation required.
|
forward | final public static void forward(ServletContext ctx, ServletRequest request, ServletResponse response, String uri, Map params, int mode) throws IOException, ServletException(Code) | | Forward to the specified URI.
It enhances RequestDispatcher in the following ways.
- It handles "~ctx"" where ctx is the context path of the
foreign context. It is called foriegn URI.
- It detects whether the page calling this method
is included by another servlet/page. If so, it uses
RequestDispatcher.include() instead of RequestDispatcher.forward().
- The forwarded page could accept additional parameters --
acutually converting parameters to a query string
and appending it to uri.
- In additions, it does HTTP encoding, i.e., converts '+' and other
characters to comply HTTP.
NOTE: don't include query parameters in uri.
Parameters: ctx - the servlet context. If null, uri cannot be foreign URI.It is ignored if URI is relevant (neither starts with '/' nor '~'). Parameters: uri - the URI to include. It is OK to relevant (without leading'/'). If starts with "/", the context path of request is assumed.To reference to foreign context, use "~ctx" where ctx is thecontext path of the foreign context (without leading '/').If it could be any context path recognized by the Web container orany name registered with Servlets.addExtendletContext. Parameters: params - the parameter map; null to ignore Parameters: mode - one of Servlets.OVERWRITE_URI, Servlets.IGNORE_PARAM,and Servlets.APPEND_PARAM. It defines how to handle if both uriand params contains the same parameter. |
getContextPaths | final public static List getContextPaths()(Code) | | Returns a list of context paths (e.g., "/abc") that this application
has. This implementation parse application.xml. For war that doesn't
contain application.xml might have to override this method and
parse another file to know what context being loaded.
|
getExtension | final public static String getExtension(String path)(Code) | | Returns the file extension of the specified path, or null
if no extension at all.
Note: the extension is converted to the lower case.
Note: it assumes the session ID, if any, starts with semicolon.
For example, the path could be "/a/b.zul;jsession=xxx".
Parameters: path - the path. If path is null, null is returned. since: 2.4.1 |
getLimitTimeOffer | final public static String getLimitTimeOffer()(Code) | | Returns a token to represent a limit-time offer.
It is mainly used as an parameter value (mostlycalled zk_lto), and then
you could verify whether it is expired by
Servlets.isOfferExpired .
|
getRequestDispatcher | final public static RequestDispatcher getRequestDispatcher(ServletContext ctx, ServletRequest request, String uri, Map params, int mode) throws ServletException(Code) | | Returns the request dispatch of the specified URI.
Parameters: ctx - the servlet context. If null, uri cannot be foreign URI.It is ignored if uri is relevant (neither starts with '/' nor '~'). Parameters: request - the request. If null, uri cannot be relevant.It is used only if uri is relevant. Parameters: uri - the URI to include. It is OK to relevant (without leading'/'). If starts with "/", the context path of request is assumed.To reference to foreign context, use "~ctx/" where ctx is thecontext path of the foreign context (without leading '/'). Parameters: params - the parameter map; null to ignore Parameters: mode - one of Servlets.OVERWRITE_URI, Servlets.IGNORE_PARAM,and Servlets.APPEND_PARAM. It defines how to handle if both uriand params contains the same parameter. |
getUserAgent | final public static String getUserAgent(ServletRequest req)(Code) | | Returns the user-agent header, which indicates what the client is,
or an empty string if not available.
Note: it doesn't return null, so it is easy to test what
the client is with
String.indexOf .
since: 3.0.2 |
include | final public static void include(ServletContext ctx, ServletRequest request, ServletResponse response, String uri, Map params, int mode) throws IOException, ServletException(Code) | | Includes the resource at the specified URI.
It enhances RequestDispatcher to allow the inclusion with
a parameter map -- acutually converting parameters to a query string
and appending it to uri.
NOTE: don't include query parameters in uri.
Parameters: ctx - the servlet context. If null, uri cannot be foreign URI.It is ignored if URI is relevant (neither starts with '/' nor '~'). Parameters: uri - the URI to include. It is OK to relevant (without leading'/'). If starts with "/", the context path of request is assumed.To reference to foreign context, use "~ctx/" where ctx is thecontext path of the foreign context (without leading '/'). Parameters: params - the parameter map; null to ignore Parameters: mode - one of Servlets.OVERWRITE_URI, Servlets.IGNORE_PARAM,and Servlets.APPEND_PARAM. It defines how to handle if both uriand params contains the same parameter. |
isExplorer7 | final public static boolean isExplorer7(ServletRequest req)(Code) | | Returns whether the browser is Explorer 7 or later.
|
isForwarded | final public static boolean isForwarded(ServletRequest request)(Code) | | Tests whether this page is forwarded by another page.
|
isGecko | final public static boolean isGecko(ServletRequest req)(Code) | | Returns whether the browser is Gecko based, such as Mozilla, Firefox and Camino
|
isHilDevice | final public static boolean isHilDevice(ServletRequest req)(Code) | | Returns whether the client is a mobile device supporting HIL
(Handset Interactive Language).
Note: ZK Mobile for Android supports both MIL and HIL.
That is, both
Servlets.isHilDevice and
Servlets.isMilDevice return true.
since: 3.0.2 |
isIncluded | final public static boolean isIncluded(ServletRequest request)(Code) | | Tests whether this page is included by another page.
|
isMilDevice | final public static boolean isMilDevice(ServletRequest req)(Code) | | Returns whether the client is a mobile device supporting MIL
(Mobile Interactive Language).
since: 2.4.0 |
isOfferExpired | final public static boolean isOfferExpired(String lto, int timeout)(Code) | | Returns whether a token returned by getLimitTimeOffer expired.
Parameters: timeout - how long the office shall expire, unit: seconds. |
isOpera | final public static boolean isOpera(ServletRequest req)(Code) | | Returns whether the browser is Opera.
|
isRobot | final public static boolean isRobot(ServletRequest req)(Code) | | Returns whether the client is a robot (such as Web crawlers).
Because there are too many robots, it returns true if the user-agent
is not recognized.
|
isSafari | final public static boolean isSafari(ServletRequest req)(Code) | | Returns whether the browser is Safari.
|
isServlet24 | final public static boolean isServlet24()(Code) | | Returns whether the current Web server supports Servlet 2.4 or above.
since: 3.0.0 |
isUniversalURL | final public static boolean isUniversalURL(String uri)(Code) | | Returns whether a URL starts with xxx://, mailto:, about:,
javascript:
|
locate | final public static String locate(ServletContext ctx, ServletRequest request, String pgpath, Locator locator) throws ServletException(Code) | | Locates a page based on the specified Locale. It never returns null.
If an URI contains "*", it will be replaced with a proper Locale.
For example, if the current Locale is zh_TW and the resource is
named "ab*.cd", then it searches "ab_zh_TW.cd", "ab_zh.cd" and
then "ab.cd", until any of them is found.
Note: "*" must be right before ".", or the last character.
For example, "ab*.cd" and "ab*" are both correct, while
"ab*cd" and "ab*\/cd" are ignored.
If an URI contains two "*", the first "*" will be replaced with
a browser code and the second with a proper locale.
The browser code depends on what browser
the user are used to visit the web site.
Currently, the code for Internet Explorer is "ie", Safari is "saf",
Opera is "opr" and all others are "moz".
Thus, in the above example, if the resource is named "ab**.cd"
and Firefox is used, then it searches "abmoz_zh_TW.cd", "abmoz_zh.cd"
and then "abmoz.cd", until any of them is found.
Note: it assumes the path as name_lang_cn_var.ext where
".ext" is optional. Example, my_zh_tw.html.jsp.
Note: unlike
Encodes.encodeURL(ServletContextServletRequestServletResponseString) ,
it always locates the Locale, without handling "*".
Parameters: ctx - the servlet context to locate pages Parameters: pgpath - the page path excluding servlet name. It is OK to havethe query string. It might contain "*" for current browser code and Locale. Parameters: locator - the locator used to locate resource. If null, ctxis assumed. pgpath if the original one matches; others if locale matches;never null |
|
|