|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjodd.servlet.ServletUtil
public class ServletUtil
Miscellaneous servlet utilities.
| Field Summary | |
|---|---|
static java.lang.String |
CONTENT_DISPOSITION
|
static java.lang.String |
HEADER_ACCEPT_ENCODING
|
static java.lang.String |
HEADER_AUTHORIZATION
|
static java.lang.String |
HEADER_CONTENT_TYPE
|
static java.lang.String |
TYPE_MULTIPART_FORM_DATA
|
static java.lang.String |
VALID_SCHEME_CHARS
Valid characters in a scheme, as specified by RFC 1738. |
static java.lang.String |
WWW_AUTHENTICATE
|
| Constructor Summary | |
|---|---|
ServletUtil()
|
|
| Method Summary | |
|---|---|
static java.lang.Object |
attrValue(javax.servlet.http.HttpServletRequest request,
java.lang.String name)
Returns non- null attribute value. |
static java.lang.Object |
attrValue(javax.servlet.jsp.PageContext pageContext,
java.lang.String name)
Returns non- null attribute value. |
static void |
copyParamsToAttributes(javax.servlet.http.HttpServletRequest servletRequest,
boolean trimParams,
boolean treatEmptyParamsAsNull,
boolean ignoreEmptyRequestParams)
Copies all request parameters to attributes. |
static java.lang.String |
debug(javax.servlet.http.HttpServletRequest request)
Returns a string with debug info from all servlet objects. |
protected static java.lang.String |
debug(javax.servlet.http.HttpServletRequest request,
javax.servlet.jsp.PageContext pageContext)
Returns a string with debug info from all servlet objects, including the page context. |
static java.lang.String |
debug(javax.servlet.jsp.PageContext pageContext)
Returns a string with debug info from all servlet objects. |
static javax.servlet.http.Cookie[] |
getAllCookies(javax.servlet.http.HttpServletRequest request,
java.lang.String cookieName)
Returns all cookies from client that matches provided name. |
static java.lang.String |
getAuthPassword(javax.servlet.http.HttpServletRequest request)
Decodes the "Authorization" header and retrieves the password from it. |
static java.lang.String |
getAuthUsername(javax.servlet.http.HttpServletRequest request)
Decodes the "Authorization" header and retrieves the user's name from it. |
static java.lang.String |
getContextPath()
|
static java.lang.String |
getContextPath(javax.servlet.http.HttpServletRequest request)
Returns correct context path, as by Servlet definition. |
static java.lang.String |
getContextPath(javax.servlet.jsp.PageContext pageContext)
|
static java.lang.String |
getContextPath(javax.servlet.ServletContext servletContext)
Returns correct context path, as by Servlet definition. |
static javax.servlet.http.Cookie |
getCookie(javax.servlet.http.HttpServletRequest request,
java.lang.String cookieName)
Finds and returns cookie from client by its name. |
static java.lang.Object |
getRequestParameter(javax.servlet.ServletRequest request,
java.lang.String name)
Returns HTTP request parameter as String or String[]. |
static java.lang.Throwable |
getServletError(javax.servlet.ServletRequest request)
Returns servlet error. |
static boolean |
isAbsoluteUrl(java.lang.String url)
Returns true if current URL is absolute, false otherwise. |
boolean |
isGetParameter(javax.servlet.http.HttpServletRequest request,
java.lang.String key)
Checks if some parameter is in GET parameters. |
static boolean |
isGzipSupported(javax.servlet.http.HttpServletRequest request)
Returns true if client supports gzip encoding. |
static boolean |
isMultipartRequest(javax.servlet.http.HttpServletRequest request)
Returns true if a request is multi-part request. |
static boolean |
isServletsVersion2_5()
Returns true if current servlets version is 2.5 or higher. |
static void |
prepareDownload(javax.servlet.http.HttpServletResponse response,
java.io.File file)
Prepares response for file download. |
static void |
prepareDownload(javax.servlet.http.HttpServletResponse response,
java.io.File file,
java.lang.String mimeType)
Prepares response for file download with specified mime type. |
static void |
prepareDownload(javax.servlet.http.HttpServletResponse response,
java.lang.String fileName,
int fileSize)
Prepares response for file download. |
static void |
prepareDownload(javax.servlet.http.HttpServletResponse response,
java.lang.String fileName,
java.lang.String mimeType,
int fileSize)
Prepares response for file download. |
static java.lang.String[] |
prepareParameters(java.lang.String[] paramValues,
boolean trimParams,
boolean treatEmptyParamsAsNull,
boolean ignoreEmptyRequestParams)
Prepares parameters for further processing. |
static void |
preventCaching(javax.servlet.http.HttpServletResponse response)
Prevents HTTP cache. |
static java.lang.String |
readRequestBody(javax.servlet.http.HttpServletRequest request)
Reads HTTP request body. |
static void |
removeScopeAttribute(java.lang.String name,
java.lang.String scope,
javax.servlet.jsp.PageContext pageContext)
Removes scope attribute. |
static void |
requireAuthentication(javax.servlet.http.HttpServletResponse resp,
java.lang.String realm)
Sends correct headers to require basic authentication for the given realm. |
static java.lang.String |
resolveUrl(java.lang.String url,
javax.servlet.http.HttpServletRequest request)
|
static java.lang.String |
resolveUrl(java.lang.String url,
javax.servlet.jsp.PageContext pageContext)
|
static java.lang.String |
resolveUrl(java.lang.String url,
java.lang.String context)
|
static void |
setScopeAttribute(java.lang.String name,
java.lang.Object value,
java.lang.String scope,
javax.servlet.jsp.PageContext pageContext)
Sets scope attribute. |
static void |
setServletError(javax.servlet.ServletRequest request,
java.lang.Throwable throwable)
Sets servlet error. |
static java.lang.String |
stripSessionId(java.lang.String url)
Strips a servlet session ID from url. |
static java.lang.Object |
value(javax.servlet.http.HttpServletRequest request,
java.lang.String name)
Returns non-null value of property/attribute. |
static java.lang.Object |
value(javax.servlet.jsp.PageContext pageContext,
java.lang.String name)
Returns non-null value of property/attribute. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String HEADER_CONTENT_TYPE
public static final java.lang.String TYPE_MULTIPART_FORM_DATA
public static final java.lang.String HEADER_AUTHORIZATION
public static final java.lang.String HEADER_ACCEPT_ENCODING
public static final java.lang.String CONTENT_DISPOSITION
public static final java.lang.String WWW_AUTHENTICATE
public static final java.lang.String VALID_SCHEME_CHARS
| Constructor Detail |
|---|
public ServletUtil()
| Method Detail |
|---|
public static boolean isMultipartRequest(javax.servlet.http.HttpServletRequest request)
true if a request is multi-part request.
public static boolean isGzipSupported(javax.servlet.http.HttpServletRequest request)
true if client supports gzip encoding.
public static java.lang.String getAuthUsername(javax.servlet.http.HttpServletRequest request)
null if the header is not present.
public static java.lang.String getAuthPassword(javax.servlet.http.HttpServletRequest request)
null if the header is not present.
public static void requireAuthentication(javax.servlet.http.HttpServletResponse resp,
java.lang.String realm)
throws java.io.IOException
java.io.IOException
public static void prepareDownload(javax.servlet.http.HttpServletResponse response,
java.io.File file)
public static void prepareDownload(javax.servlet.http.HttpServletResponse response,
java.io.File file,
java.lang.String mimeType)
public static void prepareDownload(javax.servlet.http.HttpServletResponse response,
java.lang.String fileName,
int fileSize)
public static void prepareDownload(javax.servlet.http.HttpServletResponse response,
java.lang.String fileName,
java.lang.String mimeType,
int fileSize)
response - http responsefileName - file name, if full path then file name will be stripped, if null, will be ignored.mimeType - may be nullfileSize - if less then 0 will be ignored
public static javax.servlet.http.Cookie getCookie(javax.servlet.http.HttpServletRequest request,
java.lang.String cookieName)
null if cookie with specified name doesn't exist.getAllCookies(javax.servlet.http.HttpServletRequest, String)
public static javax.servlet.http.Cookie[] getAllCookies(javax.servlet.http.HttpServletRequest request,
java.lang.String cookieName)
getCookie(javax.servlet.http.HttpServletRequest, String)
public static java.lang.String readRequestBody(javax.servlet.http.HttpServletRequest request)
throws java.io.IOException
java.io.IOExceptionpublic static java.lang.String getContextPath(javax.servlet.http.HttpServletRequest request)
The context path always comes first in a request URI. The path starts with a "/" character but does not end with a "/" character. For servlets in the default (root) context, this method returns "".
public static java.lang.String getContextPath(javax.servlet.ServletContext servletContext)
The context path always comes first in a request URI. The path starts with a "/" character but does not end with a "/" character. For servlets in the default (root) context, this method returns "".
public static java.lang.String getContextPath(javax.servlet.jsp.PageContext pageContext)
getContextPath(javax.servlet.ServletContext)public static java.lang.String getContextPath()
getContextPath(javax.servlet.ServletContext)
public static java.lang.Object getRequestParameter(javax.servlet.ServletRequest request,
java.lang.String name)
public static java.lang.Object attrValue(javax.servlet.jsp.PageContext pageContext,
java.lang.String name)
null attribute value. Scopes are examined in the
following order: page, request, session, application.
public static java.lang.Object attrValue(javax.servlet.http.HttpServletRequest request,
java.lang.String name)
null attribute value. Scopes are examined in the
following order: request, session, application.
public static java.lang.Object value(javax.servlet.jsp.PageContext pageContext,
java.lang.String name)
public static java.lang.Object value(javax.servlet.http.HttpServletRequest request,
java.lang.String name)
public static void setScopeAttribute(java.lang.String name,
java.lang.Object value,
java.lang.String scope,
javax.servlet.jsp.PageContext pageContext)
public static void removeScopeAttribute(java.lang.String name,
java.lang.String scope,
javax.servlet.jsp.PageContext pageContext)
public static boolean isAbsoluteUrl(java.lang.String url)
true if current URL is absolute, false otherwise.
public static java.lang.String stripSessionId(java.lang.String url)
url. The session ID
is encoded as a URL "path parameter" beginning with "jsessionid=".
We thus remove anything we find between ";jsessionid=" (inclusive)
and either EOS or a subsequent ';' (exclusive).
public static java.lang.String resolveUrl(java.lang.String url,
javax.servlet.jsp.PageContext pageContext)
public static java.lang.String resolveUrl(java.lang.String url,
javax.servlet.http.HttpServletRequest request)
public static java.lang.String resolveUrl(java.lang.String url,
java.lang.String context)
public boolean isGetParameter(javax.servlet.http.HttpServletRequest request,
java.lang.String key)
public static java.lang.String[] prepareParameters(java.lang.String[] paramValues,
boolean trimParams,
boolean treatEmptyParamsAsNull,
boolean ignoreEmptyRequestParams)
paramValues - string array of param valuestrimParams - trim parameterstreatEmptyParamsAsNull - empty parameters should be treated as nullignoreEmptyRequestParams - if all parameters are empty, return null
public static void copyParamsToAttributes(javax.servlet.http.HttpServletRequest servletRequest,
boolean trimParams,
boolean treatEmptyParamsAsNull,
boolean ignoreEmptyRequestParams)
public static boolean isServletsVersion2_5()
true if current servlets version is 2.5 or higher.
public static java.lang.Throwable getServletError(javax.servlet.ServletRequest request)
public static void setServletError(javax.servlet.ServletRequest request,
java.lang.Throwable throwable)
public static java.lang.String debug(javax.servlet.http.HttpServletRequest request)
debug(HttpServletRequest, PageContext)public static java.lang.String debug(javax.servlet.jsp.PageContext pageContext)
debug(HttpServletRequest, PageContext)
protected static java.lang.String debug(javax.servlet.http.HttpServletRequest request,
javax.servlet.jsp.PageContext pageContext)
public static void preventCaching(javax.servlet.http.HttpServletResponse response)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||