|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectfc.web.servlet.WebUtil
public final class WebUtil
Misc web related utility functions
Constructor Summary | |
---|---|
WebUtil()
|
Method Summary | |
---|---|
static java.lang.String |
absoluteEncPath(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
java.lang.String path)
URL encodes and returns the path obtained via absolutePath(javax.servlet.http.HttpServletRequest, java.lang.String) . |
static java.lang.String |
absolutePath(javax.servlet.http.HttpServletRequest req,
java.lang.String path)
Creates an absolute path starting from the web document root directory. |
static void |
clientRedirect(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
java.lang.String location)
Redirects the browser to the specified URL via a client side redirect URL. |
static void |
debugRequestParams(javax.servlet.http.HttpServletRequest req)
writes all request params received in the specied request to System.out. |
static void |
debugRequestParams(javax.servlet.http.HttpServletRequest req,
java.io.OutputStream out)
writes all request params received in the specied request to the specified output stream. |
static void |
forward(javax.servlet.http.HttpServletRequest req,
javax.servlet.http.HttpServletResponse res,
java.lang.String URL)
Redirects the request (server side redirect) to the specified relative URL via the ServletRequest.getRequestDispatcher(java.lang.String) . |
static java.lang.Object |
getAttribute(javax.servlet.http.HttpServletRequest request,
java.lang.String name,
java.lang.String backup)
Gets the specified attribute from the request object. |
static java.lang.Object |
getAttribute(javax.servlet.ServletContext context,
java.lang.String name,
java.lang.String backup)
Gets the specified attribute from the servlet context. |
static boolean |
getBooleanParameter(javax.servlet.http.HttpServletRequest request,
java.lang.String name)
Convenience method that returns the specified parameter as a boolean value. |
static javax.servlet.http.Cookie |
getCookie(javax.servlet.http.HttpServletRequest req,
java.lang.String cookieName)
Returns the cookie with the specified name or null if no cookie was found. |
static java.lang.String |
getParam(javax.servlet.http.HttpServletRequest request,
java.lang.String name,
java.lang.String backup)
Gets the specified parameter from the request object. |
static java.lang.String |
getParam(javax.servlet.ServletContext context,
java.lang.String name,
java.lang.String backup)
Gets the specified initialization parameter from the servlet context. |
static java.lang.String |
getParam(javax.servlet.Servlet servlet,
java.lang.String name,
java.lang.String backup)
Gets the specified initialization parameter for the specified servlet (via it's ServletConfig). |
static java.lang.StringBuffer |
getRequestURL(javax.servlet.http.HttpServletRequest req)
|
static java.lang.Object |
getRequiredAttribute(javax.servlet.http.HttpServletRequest request,
java.lang.String name)
Gets the specified required attribute from the request object. |
static java.lang.Object |
getRequiredAttribute(javax.servlet.ServletContext context,
java.lang.String name)
Gets the specified required attribute from the servlet context. |
static java.lang.String |
getRequiredParam(javax.servlet.http.HttpServletRequest request,
java.lang.String name)
Gets the specified required parameter from the request object. |
static java.lang.String |
getRequiredParam(javax.servlet.ServletContext context,
java.lang.String name)
Gets the specified required initialization parameter from the servlet context. |
static java.lang.String |
getRequiredParam(javax.servlet.Servlet servlet,
java.lang.String name)
Gets the specified initialization parameter for the specified servlet (via it's ServletConfig). |
static java.lang.String |
getSessionString(javax.servlet.http.HttpSession session,
java.lang.String name)
Returns a HttpSession attribute as a String or null if the attribute was absent. |
static boolean |
isIOSClient(javax.servlet.http.HttpServletRequest req)
Returns true if the client is an iOS mobile device. |
static boolean |
isMobileClient(javax.servlet.http.HttpServletRequest req)
Returns true if the client is a mobile device |
static boolean |
isSelected(javax.servlet.http.HttpServletRequest request,
java.lang.String name)
The returned value will be true if the specified parameter is present in the request and is a non-null non-empty string (of any value). |
static java.util.Map |
parseQuery(java.lang.String query)
|
static boolean |
requestCancelled(javax.servlet.http.HttpServletRequest req)
Returns true only if a request parameter with the name confirm is seen. |
static boolean |
requestConfirmed(javax.servlet.http.HttpServletRequest req)
Returns true only if a request parameter with the name cancel is seen. |
static void |
setExpireHeaders(javax.servlet.http.HttpServletResponse res)
set expire headers to cover all cases |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public WebUtil()
Method Detail |
---|
public static final java.lang.String getRequiredParam(javax.servlet.ServletContext context, java.lang.String name) throws javax.servlet.ServletException
UnavailableException
.
javax.servlet.ServletException
public static final java.lang.String getParam(javax.servlet.ServletContext context, java.lang.String name, java.lang.String backup)
public static final java.lang.String getRequiredParam(javax.servlet.Servlet servlet, java.lang.String name) throws javax.servlet.ServletException
UnavailableException
.
javax.servlet.ServletException
public static final java.lang.String getParam(javax.servlet.Servlet servlet, java.lang.String name, java.lang.String backup)
public static final java.lang.String getRequiredParam(javax.servlet.http.HttpServletRequest request, java.lang.String name) throws javax.servlet.ServletException
javax.servlet.ServletException
public static final java.lang.String getParam(javax.servlet.http.HttpServletRequest request, java.lang.String name, java.lang.String backup)
public static final boolean isSelected(javax.servlet.http.HttpServletRequest request, java.lang.String name)
public static final boolean getBooleanParameter(javax.servlet.http.HttpServletRequest request, java.lang.String name)
Boolean.parseBoolean(String)
(for true, the
value should be non-null and equal ignore case to "true").
public static final java.lang.Object getRequiredAttribute(javax.servlet.ServletContext context, java.lang.String name) throws javax.servlet.ServletException
UnavailableException
.
javax.servlet.ServletException
public static final java.lang.Object getAttribute(javax.servlet.ServletContext context, java.lang.String name, java.lang.String backup) throws javax.servlet.ServletException
javax.servlet.ServletException
public static final java.lang.Object getRequiredAttribute(javax.servlet.http.HttpServletRequest request, java.lang.String name) throws javax.servlet.ServletException
javax.servlet.ServletException
public static final java.lang.Object getAttribute(javax.servlet.http.HttpServletRequest request, java.lang.String name, java.lang.String backup) throws javax.servlet.ServletException
javax.servlet.ServletException
public static final java.lang.String getSessionString(javax.servlet.http.HttpSession session, java.lang.String name)
name
- the name of the session attribute
java.lang.ClassCastException
- if the attribute was not a String
java.lang.NullPointerException
- if the specified session or name parameters
were nullpublic static javax.servlet.http.Cookie getCookie(javax.servlet.http.HttpServletRequest req, java.lang.String cookieName)
public static final void forward(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, java.lang.String URL) throws javax.servlet.ServletException, java.io.IOException
ServletRequest.getRequestDispatcher(java.lang.String)
. See
RequestDispatcher.forward(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
for restrictions while
forwarding to another page (in particular, the response must not have been
committed before calling this method).
The calling code must have a return statement immediately after calling this method, otherwise RequestDispatching will probably not work as intended.
req
- the current requestres
- the current responseURL
- The pathname specified may be relative, although it
cannot extend outside the current servlet context. If the
path begins with a "/" it is interpreted as starting from
the root of the current context. (i.e., the webapp context,
if present, does not need to be specified).
javax.servlet.ServletException
java.io.IOException
public static final void clientRedirect(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, java.lang.String location) throws javax.servlet.ServletException, java.io.IOException
Response.sentRedirect
Session information is preserved if using container provided URL-based sessions.
If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to.
req
- the current requestres
- the current responselocation
- See
javax.servlet.http.HttpResponse#sendRedirect
.
Essentially, the location can be relative to the
specified request's URI or relative to the
context root if it contains a leading '/'
javax.servlet.ServletException
java.io.IOException
public static final java.lang.String absolutePath(javax.servlet.http.HttpServletRequest req, java.lang.String path)
absoluteEncPath(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.String)
).
This method should be used for all HTML links (in html pages and forms) and also for client side redirects. This ensures the ability to move the calling code to a different web app (other than the default root ("/") web app). If it's certain that there will always only be 1 web app (the default) then calling this method is not necessary.
Note also that server-side redirects and includes (with RequestDispatcher) should *not* use this method since all such server side redirects etc automatically work as expected inside the web app context and are always relative to the web app context itself.
req
- the current HttpServletRequestpath
- an absolute path starting from the root of
the context associated with the request.
If the current webapp (context) is /foo and
the specified path is /bar, then this
method will return /foo/barpublic static final java.lang.String absoluteEncPath(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse res, java.lang.String path)
absolutePath(javax.servlet.http.HttpServletRequest, java.lang.String)
.
public static final java.lang.StringBuffer getRequestURL(javax.servlet.http.HttpServletRequest req)
RequestURL
method in HttpServletRequest does not return the query part of the URL)public static final boolean requestCancelled(javax.servlet.http.HttpServletRequest req)
public static final boolean requestConfirmed(javax.servlet.http.HttpServletRequest req)
public static final void debugRequestParams(javax.servlet.http.HttpServletRequest req)
public static final void debugRequestParams(javax.servlet.http.HttpServletRequest req, java.io.OutputStream out)
public static final void setExpireHeaders(javax.servlet.http.HttpServletResponse res)
public static java.util.Map parseQuery(java.lang.String query) throws java.io.UnsupportedEncodingException
java.io.UnsupportedEncodingException
public static boolean isMobileClient(javax.servlet.http.HttpServletRequest req)
public static boolean isIOSClient(javax.servlet.http.HttpServletRequest req)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |