|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.springframework.web.util.WebUtils
public abstract class WebUtils
Miscellaneous utilities for web applications. Used by various framework classes.
Field Detail |
---|
public static final java.lang.String INCLUDE_REQUEST_URI_ATTRIBUTE
If included via a RequestDispatcher, the current resource will see the originating request. Its own URI and paths are exposed as request attributes.
public static final java.lang.String INCLUDE_CONTEXT_PATH_ATTRIBUTE
public static final java.lang.String INCLUDE_SERVLET_PATH_ATTRIBUTE
public static final java.lang.String INCLUDE_PATH_INFO_ATTRIBUTE
public static final java.lang.String INCLUDE_QUERY_STRING_ATTRIBUTE
public static final java.lang.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 java.lang.String FORWARD_CONTEXT_PATH_ATTRIBUTE
public static final java.lang.String FORWARD_SERVLET_PATH_ATTRIBUTE
public static final java.lang.String FORWARD_PATH_INFO_ATTRIBUTE
public static final java.lang.String FORWARD_QUERY_STRING_ATTRIBUTE
public static final java.lang.String ERROR_STATUS_CODE_ATTRIBUTE
To be exposed to JSPs that are marked as error pages, when forwarding to them directly rather than through the servlet container's error page resolution mechanism.
public static final java.lang.String ERROR_EXCEPTION_TYPE_ATTRIBUTE
public static final java.lang.String ERROR_MESSAGE_ATTRIBUTE
public static final java.lang.String ERROR_EXCEPTION_ATTRIBUTE
public static final java.lang.String ERROR_REQUEST_URI_ATTRIBUTE
public static final java.lang.String ERROR_SERVLET_NAME_ATTRIBUTE
public static final java.lang.String CONTENT_TYPE_CHARSET_PREFIX
public static final java.lang.String DEFAULT_CHARACTER_ENCODING
request.getCharacterEncoding
returns null
, according to the Servlet spec.
ServletRequest.getCharacterEncoding()
,
Constant Field Valuespublic static final java.lang.String TEMP_DIR_CONTEXT_ATTRIBUTE
java.io.File
.
public static final java.lang.String HTML_ESCAPE_CONTEXT_PARAM
web.xml
): "defaultHtmlEscape".
public static final java.lang.String WEB_APP_ROOT_KEY_PARAM
web.xml
): "webAppRootKey".
public static final java.lang.String DEFAULT_WEB_APP_ROOT_KEY
public static final java.lang.String[] SUBMIT_IMAGE_SUFFIXES
public static final java.lang.String SESSION_MUTEX_ATTRIBUTE
Constructor Detail |
---|
public WebUtils()
Method Detail |
---|
public static void setWebAppRootSystemProperty(javax.servlet.ServletContext servletContext) throws java.lang.IllegalStateException
web.xml
. Default is "webapp.root".
Can be used for tools that support substition with System.getProperty
values, like log4j's "${key}" syntax within log file locations.
servletContext
- the servlet context of the web application
java.lang.IllegalStateException
- if the system property is already set,
or if the WAR file is not expandedWEB_APP_ROOT_KEY_PARAM
,
DEFAULT_WEB_APP_ROOT_KEY
,
WebAppRootListener
,
Log4jWebConfigurer
public static void removeWebAppRootSystemProperty(javax.servlet.ServletContext servletContext)
servletContext
- the servlet context of the web applicationsetWebAppRootSystemProperty(javax.servlet.ServletContext)
public static boolean isDefaultHtmlEscape(javax.servlet.ServletContext servletContext)
web.xml
(if any). Falls back to false
in case of no explicit default given.
servletContext
- the servlet context of the web application
public static java.lang.Boolean getDefaultHtmlEscape(javax.servlet.ServletContext servletContext)
web.xml
(if any).
This method differentiates between no param specified at all and an actual boolean value specified, allowing to have a context-specific default in case of no setting at the global level.
servletContext
- the servlet context of the web application
public static java.io.File getTempDir(javax.servlet.ServletContext servletContext)
servletContext
- the servlet context of the web application
public static java.lang.String getRealPath(javax.servlet.ServletContext servletContext, java.lang.String path) throws java.io.FileNotFoundException
Prepends a slash if the path does not already start with a slash,
and throws a FileNotFoundException if the path cannot be resolved to
a resource (in contrast to ServletContext's getRealPath
,
which returns null).
servletContext
- the servlet context of the web applicationpath
- the path within the web application
java.io.FileNotFoundException
- if the path cannot be resolved to a resourceServletContext.getRealPath(java.lang.String)
public static java.lang.String getSessionId(javax.servlet.http.HttpServletRequest request)
request
- current HTTP request
null
if nonepublic static java.lang.Object getSessionAttribute(javax.servlet.http.HttpServletRequest request, java.lang.String name)
request
- current HTTP requestname
- the name of the session attribute
null
if not foundpublic static java.lang.Object getRequiredSessionAttribute(javax.servlet.http.HttpServletRequest request, java.lang.String name) throws java.lang.IllegalStateException
request
- current HTTP requestname
- the name of the session attribute
null
if not found
java.lang.IllegalStateException
- if the session attribute could not be foundpublic static void setSessionAttribute(javax.servlet.http.HttpServletRequest request, java.lang.String name, java.lang.Object value)
request
- current HTTP requestname
- the name of the session attributevalue
- the value of the session attributepublic static java.lang.Object getOrCreateSessionAttribute(javax.servlet.http.HttpSession session, java.lang.String name, java.lang.Class clazz) throws java.lang.IllegalArgumentException
session
- current HTTP sessionname
- the name of the session attributeclazz
- the class to instantiate for a new attribute
java.lang.IllegalArgumentException
- if the session attribute could not be instantiatedpublic static java.lang.Object getSessionMutex(javax.servlet.http.HttpSession session)
Returns the session mutex attribute if available; usually,
this means that the HttpSessionMutexListener needs to be defined
in web.xml
. Falls back to the HttpSession itself
if no mutex attribute found.
The session mutex is guaranteed to be the same object during
the entire lifetime of the session, available under the key defined
by the SESSION_MUTEX_ATTRIBUTE
constant. It serves as a
safe reference to synchronize on for locking on the current session.
In many cases, the HttpSession reference itself is a safe mutex as well, since it will always be the same object reference for the same active logical session. However, this is not guaranteed across different servlet containers; the only 100% safe way is a session mutex.
session
- the HttpSession to find a mutex for
null
)SESSION_MUTEX_ATTRIBUTE
,
HttpSessionMutexListener
public static boolean isIncludeRequest(javax.servlet.ServletRequest request)
Checks the presence of the "javax.servlet.include.request_uri" request attribute. Could check any request attribute that is only present in an include request.
request
- current servlet request
public static void exposeForwardRequestAttributes(javax.servlet.http.HttpServletRequest request)
HttpServletRequest
attributes under the keys defined in the Servlet 2.4 specification,
for containers that implement 2.3 or an earlier version of the Servlet API:
javax.servlet.forward.request_uri
,
javax.servlet.forward.context_path
,
javax.servlet.forward.servlet_path
,
javax.servlet.forward.path_info
,
javax.servlet.forward.query_string
.
Does not override values if already present, to not cause conflicts with the attributes exposed by Servlet 2.4+ containers themselves.
request
- current servlet requestpublic static void exposeErrorRequestAttributes(javax.servlet.http.HttpServletRequest request, java.lang.Throwable ex, java.lang.String servletName)
HttpServletRequest
attributes under the keys defined in the Servlet 2.3 specification, for error pages that
are rendered directly rather than through the Servlet container's error page resolution:
javax.servlet.error.status_code
,
javax.servlet.error.exception_type
,
javax.servlet.error.message
,
javax.servlet.error.exception
,
javax.servlet.error.request_uri
,
javax.servlet.error.servlet_name
.
Does not override values if already present, to respect attribute values that have been exposed explicitly before.
Exposes status code 200 by default. Set the "javax.servlet.error.status_code" attribute explicitly (before or after) in order to expose a different status code.
request
- current servlet requestex
- the exception encounteredservletName
- the name of the offending servletprivate static void exposeRequestAttributeIfNotPresent(javax.servlet.ServletRequest request, java.lang.String name, java.lang.Object value)
request
- current servlet requestname
- the name of the attributevalue
- the suggested value of the attributepublic static void clearErrorRequestAttributes(javax.servlet.http.HttpServletRequest request)
HttpServletRequest
attributes under the keys defined in the Servlet 2.3 specification:
javax.servlet.error.status_code
,
javax.servlet.error.exception_type
,
javax.servlet.error.message
,
javax.servlet.error.exception
,
javax.servlet.error.request_uri
,
javax.servlet.error.servlet_name
.
request
- current servlet requestpublic static void exposeRequestAttributes(javax.servlet.ServletRequest request, java.util.Map<java.lang.String,?> attributes)
request
- current HTTP requestattributes
- the attributes Mappublic static javax.servlet.http.Cookie getCookie(javax.servlet.http.HttpServletRequest request, java.lang.String name)
request
- current servlet requestname
- cookie name
null
if none is foundpublic static boolean hasSubmitParameter(javax.servlet.ServletRequest request, java.lang.String name)
request
- current HTTP requestname
- name of the parameter
SUBMIT_IMAGE_SUFFIXES
public static java.lang.String findParameterValue(javax.servlet.ServletRequest request, java.lang.String name)
See findParameterValue(java.util.Map, String)
for a description of the lookup algorithm.
request
- current HTTP requestname
- the logical name of the request parameter
null
if the parameter does not exist in given requestpublic static java.lang.String findParameterValue(java.util.Map<java.lang.String,?> parameters, java.lang.String name)
This method will try to obtain a parameter value using the following algorithm:
parameters
- the available parameter mapname
- the logical name of the request parameter
null
if the parameter does not exist in given requestpublic static java.util.Map<java.lang.String,java.lang.Object> getParametersStartingWith(javax.servlet.ServletRequest request, java.lang.String prefix)
For example, with a prefix of "spring_", "spring_param1" and "spring_param2" result in a Map with "param1" and "param2" as keys.
request
- HTTP request in which to look for parametersprefix
- the beginning of parameter names
(if this is null or the empty string, all parameters will match)
ServletRequest.getParameterNames()
,
ServletRequest.getParameterValues(java.lang.String)
,
ServletRequest.getParameterMap()
public static int getTargetPage(javax.servlet.ServletRequest request, java.lang.String paramPrefix, int currentPage)
request
- current servlet requestparamPrefix
- the parameter prefix to check for
(e.g. "_target" for parameters like "_target1" or "_target2")currentPage
- the current page, to be returned as fallback
if no target page specified
public static java.lang.String extractFilenameFromUrlPath(java.lang.String urlPath)
urlPath
- the request URL path (e.g. "/index.html")
public static java.lang.String extractFullFilenameFromUrlPath(java.lang.String urlPath)
urlPath
- the request URL path (e.g. "/products/index.html")
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |