|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.web.util.WebUtils
Miscellaneous utilities for web applications. Used by various framework classes.
Field Summary | |
static String |
DEFAULT_CHARACTER_ENCODING
Default character encoding to use when request.getCharacterEncoding returns null, according to the Servlet spec. |
static String |
DEFAULT_WEB_APP_ROOT_KEY
Default web app root key: "webapp.root" |
static String |
HTML_ESCAPE_CONTEXT_PARAM
HTML escape parameter at the servlet context level (i.e. a context-param in web.xml): "defaultHtmlEscape". |
static String[] |
SUBMIT_IMAGE_SUFFIXES
Name suffixes in case of image buttons |
static String |
TEMP_DIR_CONTEXT_ATTRIBUTE
Standard Servlet spec context attribute that specifies a temporary directory for the current web application, of type java.io.File |
static String |
WEB_APP_ROOT_KEY_PARAM
Web app root key parameter at the servlet context level (i.e. a context-param in web.xml): "webAppRootKey". |
Constructor Summary | |
WebUtils()
|
Method Summary | |
static void |
exposeRequestAttributes(ServletRequest request,
Map attributes)
Expose the given Map as request attributes, using the keys as attribute names and the values as corresponding attribute values. |
static Cookie |
getCookie(HttpServletRequest request,
String name)
Retrieve the first cookie with the given name. |
static Object |
getOrCreateSessionAttribute(HttpSession session,
String name,
Class clazz)
Get the specified session attribute, creating and setting a new attribute if no existing found. |
static Map |
getParametersStartingWith(ServletRequest request,
String prefix)
Return a map containing all parameters with the given prefix. |
static Object |
getRequiredSessionAttribute(HttpServletRequest request,
String name)
Check the given request for a session attribute of the given name. |
static Object |
getSessionAttribute(HttpServletRequest request,
String name)
Check the given request for a session attribute of the given name. |
static String |
getSessionId(HttpServletRequest request)
Determine the session id of the given request, if any. |
static File |
getTempDir(ServletContext servletContext)
Return the temporary directory for the current web application, as provided by the servlet container. |
static boolean |
hasSubmitParameter(ServletRequest request,
String name)
Check if a specific input type="submit" parameter was sent in the request, either via a button (directly with name) or via an image (name + ".x" or name + ".y"). |
static boolean |
isDefaultHtmlEscape(ServletContext servletContext)
Return whether default HTML escaping is enabled for the web application, i.e. the value of the "defaultHtmlEscape" context-param in web.xml (if any). |
static void |
removeWebAppRootSystemProperty(ServletContext servletContext)
Remove the system property that points to the web app root directory. |
static void |
setSessionAttribute(HttpServletRequest request,
String name,
Object value)
Set the session attribute with the given name to the given value. |
static void |
setWebAppRootSystemProperty(ServletContext servletContext)
Set a system property to the web application root directory. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final String DEFAULT_CHARACTER_ENCODING
ServletRequest.getCharacterEncoding()
,
Constant Field Valuespublic static final String TEMP_DIR_CONTEXT_ATTRIBUTE
public static final String HTML_ESCAPE_CONTEXT_PARAM
public static final String WEB_APP_ROOT_KEY_PARAM
public static final String DEFAULT_WEB_APP_ROOT_KEY
public static final String[] SUBMIT_IMAGE_SUFFIXES
Constructor Detail |
public WebUtils()
Method Detail |
public static void setWebAppRootSystemProperty(ServletContext servletContext) throws IllegalStateException
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
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(ServletContext servletContext)
servletContext
- the servlet context of the web applicationsetWebAppRootSystemProperty(javax.servlet.ServletContext)
public static boolean isDefaultHtmlEscape(ServletContext servletContext)
servletContext
- the servlet context of the web application
public static File getTempDir(ServletContext servletContext)
servletContext
- the servlet context of the web application
public static String getSessionId(HttpServletRequest request)
request
- current HTTP request
public static Object getSessionAttribute(HttpServletRequest request, String name)
request
- current HTTP requestname
- the name of the session attribute
public static Object getRequiredSessionAttribute(HttpServletRequest request, String name) throws IllegalStateException
request
- current HTTP requestname
- the name of the session attribute
IllegalStateException
- if the session attribute could not be foundpublic static void setSessionAttribute(HttpServletRequest request, String name, Object value)
request
- current HTTP requestname
- the name of the session attributepublic static Object getOrCreateSessionAttribute(HttpSession session, String name, Class clazz) throws IllegalArgumentException
session
- current HTTP sessionname
- the name of the session attributeclazz
- the class to instantiate for a new attribute
IllegalArgumentException
- if the session attribute could not be instantiatedpublic static void exposeRequestAttributes(ServletRequest request, Map attributes) throws IllegalArgumentException
request
- current HTTP requestattributes
- the attributes Map
IllegalArgumentException
- if an invalid key is found in the Mappublic static Cookie getCookie(HttpServletRequest request, String name)
name
- cookie name
public static boolean hasSubmitParameter(ServletRequest request, String name)
request
- current HTTP requestname
- name of the parameter
SUBMIT_IMAGE_SUFFIXES
public static Map getParametersStartingWith(ServletRequest request, String prefix)
For example, with a prefix of "spring_", "spring_param1" and "spring_param2" result in a Map with "param1" and "param2" as keys.
Similar to Servlet 2.3's ServletRequest.getParameterMap
,
but more flexible and compatible with Servlet 2.2.
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()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |