Java Doc for WebUtils.java in  » J2EE » spring-framework-2.0.6 » org » springframework » web » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » spring framework 2.0.6 » org.springframework.web.util 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   org.springframework.web.util.WebUtils

WebUtils
abstract public class WebUtils (Code)
Miscellaneous utilities for web applications. Used by various framework classes.
author:
   Rod Johnson
author:
   Juergen Hoeller


Field Summary
final public static  StringCONTENT_TYPE_CHARSET_PREFIX
    
final public static  StringDEFAULT_CHARACTER_ENCODING
     Default character encoding to use when request.getCharacterEncoding returns null, according to the Servlet spec.
final public static  StringDEFAULT_WEB_APP_ROOT_KEY
    
final public static  StringFORWARD_CONTEXT_PATH_ATTRIBUTE
    
final public static  StringFORWARD_PATH_INFO_ATTRIBUTE
    
final public static  StringFORWARD_QUERY_STRING_ATTRIBUTE
    
final public static  StringFORWARD_REQUEST_URI_ATTRIBUTE
     Standard Servlet 2.4+ spec request attributes for forward URI and paths.

If forwarded to via a RequestDispatcher, the current resource will see its own URI and paths.

final public static  StringFORWARD_SERVLET_PATH_ATTRIBUTE
    
final public static  StringHTML_ESCAPE_CONTEXT_PARAM
     HTML escape parameter at the servlet context level (i.e.
final public static  StringINCLUDE_CONTEXT_PATH_ATTRIBUTE
    
final public static  StringINCLUDE_PATH_INFO_ATTRIBUTE
    
final public static  StringINCLUDE_QUERY_STRING_ATTRIBUTE
    
final public static  StringINCLUDE_REQUEST_URI_ATTRIBUTE
     Standard Servlet 2.3+ spec request attributes for include URI and paths.

If included via a RequestDispatcher, the current resource will see the originating request.

final public static  StringINCLUDE_SERVLET_PATH_ATTRIBUTE
    
final public static  StringSESSION_MUTEX_ATTRIBUTE
    
final public static  String[]SUBMIT_IMAGE_SUFFIXES
    
final public static  StringTEMP_DIR_CONTEXT_ATTRIBUTE
     Standard Servlet spec context attribute that specifies a temporary directory for the current web application, of type java.io.File.
final public static  StringWEB_APP_ROOT_KEY_PARAM
     Web app root key parameter at the servlet context level (i.e.


Method Summary
public static  voidexposeForwardRequestAttributes(HttpServletRequest request)
     Expose the current request URI and paths as javax.servlet.http.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.
public static  voidexposeRequestAttributes(ServletRequest request, Map attributes)
     Expose the given Map as request attributes, using the keys as attribute names and the values as corresponding attribute values.
public static  StringextractFilenameFromUrlPath(String urlPath)
     Extract the URL filename from the given request URL path. Correctly resolves nested paths such as "/products/view.html" as well.
Parameters:
  urlPath - the request URL path (e.g.
public static  CookiegetCookie(HttpServletRequest request, String name)
     Retrieve the first cookie with the given name.
public static  ObjectgetOrCreateSessionAttribute(HttpSession session, String name, Class clazz)
     Get the specified session attribute, creating and setting a new attribute if no existing found.
public static  MapgetParametersStartingWith(ServletRequest request, String prefix)
     Return a map containing all parameters with the given prefix.
public static  StringgetRealPath(ServletContext servletContext, String path)
     Return the real path of the given path within the web application, as provided by the servlet container.
public static  ObjectgetRequiredSessionAttribute(HttpServletRequest request, String name)
     Check the given request for a session attribute of the given name. Throws an exception if there is no session or if the session has no such attribute.
public static  ObjectgetSessionAttribute(HttpServletRequest request, String name)
     Check the given request for a session attribute of the given name.
public static  StringgetSessionId(HttpServletRequest request)
     Determine the session id of the given request, if any.
public static  ObjectgetSessionMutex(HttpSession session)
     Return the best available mutex for the given session: that is, an object to synchronize on for the given session.

Returns the session mutex attribute if available; usually, this means that the HttpSessionMutexListener needs to be defined in web.xml.

public static  FilegetTempDir(ServletContext servletContext)
     Return the temporary directory for the current web application, as provided by the servlet container.
public static  booleanhasSubmitParameter(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").
public static  booleanisDefaultHtmlEscape(ServletContext servletContext)
     Return whether default HTML escaping is enabled for the web application, i.e.
public static  booleanisIncludeRequest(ServletRequest request)
     Determine whether the given request is an include request, that is, not a top-level HTTP request coming in from the outside.

Checks the presence of the "javax.servlet.include.request_uri" request attribute.

public static  voidremoveWebAppRootSystemProperty(ServletContext servletContext)
     Remove the system property that points to the web app root directory.
public static  voidsetSessionAttribute(HttpServletRequest request, String name, Object value)
     Set the session attribute with the given name to the given value.
public static  voidsetWebAppRootSystemProperty(ServletContext servletContext)
     Set a system property to the web application root directory. The key of the system property can be defined with the "webAppRootKey" context-param in web.xml.

Field Detail
CONTENT_TYPE_CHARSET_PREFIX
final public static String CONTENT_TYPE_CHARSET_PREFIX(Code)
Prefix of the charset clause in a content type String: ";charset="



DEFAULT_CHARACTER_ENCODING
final public static String DEFAULT_CHARACTER_ENCODING(Code)
Default character encoding to use when request.getCharacterEncoding returns null, according to the Servlet spec.
See Also:   ServletRequest.getCharacterEncoding



DEFAULT_WEB_APP_ROOT_KEY
final public static String DEFAULT_WEB_APP_ROOT_KEY(Code)
Default web app root key: "webapp.root"



FORWARD_CONTEXT_PATH_ATTRIBUTE
final public static String FORWARD_CONTEXT_PATH_ATTRIBUTE(Code)



FORWARD_PATH_INFO_ATTRIBUTE
final public static String FORWARD_PATH_INFO_ATTRIBUTE(Code)



FORWARD_QUERY_STRING_ATTRIBUTE
final public static String FORWARD_QUERY_STRING_ATTRIBUTE(Code)



FORWARD_REQUEST_URI_ATTRIBUTE
final public static String FORWARD_REQUEST_URI_ATTRIBUTE(Code)
Standard Servlet 2.4+ spec request attributes for forward URI and paths.

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.




FORWARD_SERVLET_PATH_ATTRIBUTE
final public static String FORWARD_SERVLET_PATH_ATTRIBUTE(Code)



HTML_ESCAPE_CONTEXT_PARAM
final public static String HTML_ESCAPE_CONTEXT_PARAM(Code)
HTML escape parameter at the servlet context level (i.e. a context-param in web.xml): "defaultHtmlEscape".



INCLUDE_CONTEXT_PATH_ATTRIBUTE
final public static String INCLUDE_CONTEXT_PATH_ATTRIBUTE(Code)



INCLUDE_PATH_INFO_ATTRIBUTE
final public static String INCLUDE_PATH_INFO_ATTRIBUTE(Code)



INCLUDE_QUERY_STRING_ATTRIBUTE
final public static String INCLUDE_QUERY_STRING_ATTRIBUTE(Code)



INCLUDE_REQUEST_URI_ATTRIBUTE
final public static String INCLUDE_REQUEST_URI_ATTRIBUTE(Code)
Standard Servlet 2.3+ spec request attributes for include URI and paths.

If included via a RequestDispatcher, the current resource will see the originating request. Its own URI and paths are exposed as request attributes.




INCLUDE_SERVLET_PATH_ATTRIBUTE
final public static String INCLUDE_SERVLET_PATH_ATTRIBUTE(Code)



SESSION_MUTEX_ATTRIBUTE
final public static String SESSION_MUTEX_ATTRIBUTE(Code)
Key for the mutex session attribute



SUBMIT_IMAGE_SUFFIXES
final public static String[] SUBMIT_IMAGE_SUFFIXES(Code)
Name suffixes in case of image buttons



TEMP_DIR_CONTEXT_ATTRIBUTE
final public static String TEMP_DIR_CONTEXT_ATTRIBUTE(Code)
Standard Servlet spec context attribute that specifies a temporary directory for the current web application, of type java.io.File.



WEB_APP_ROOT_KEY_PARAM
final public static String WEB_APP_ROOT_KEY_PARAM(Code)
Web app root key parameter at the servlet context level (i.e. a context-param in web.xml): "webAppRootKey".





Method Detail
exposeForwardRequestAttributes
public static void exposeForwardRequestAttributes(HttpServletRequest request)(Code)
Expose the current request URI and paths as javax.servlet.http.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.
Parameters:
  request - current servlet request




exposeRequestAttributes
public static void exposeRequestAttributes(ServletRequest request, Map attributes) throws IllegalArgumentException(Code)
Expose the given Map as request attributes, using the keys as attribute names and the values as corresponding attribute values. Keys need to be Strings.
Parameters:
  request - current HTTP request
Parameters:
  attributes - the attributes Map
throws:
  IllegalArgumentException - if an invalid key is found in the Map



extractFilenameFromUrlPath
public static String extractFilenameFromUrlPath(String urlPath)(Code)
Extract the URL filename from the given request URL path. Correctly resolves nested paths such as "/products/view.html" as well.
Parameters:
  urlPath - the request URL path (e.g. "/index.html") the extracted URI filename (e.g. "index")



getCookie
public static Cookie getCookie(HttpServletRequest request, String name)(Code)
Retrieve the first cookie with the given name. Note that multiple cookies can have the same name but different paths or domains.
Parameters:
  request - current servlet request
Parameters:
  name - cookie name the first cookie with the given name, or null if none is found



getOrCreateSessionAttribute
public static Object getOrCreateSessionAttribute(HttpSession session, String name, Class clazz) throws IllegalArgumentException(Code)
Get the specified session attribute, creating and setting a new attribute if no existing found. The given class needs to have a public no-arg constructor. Useful for on-demand state objects in a web tier, like shopping carts.
Parameters:
  session - current HTTP session
Parameters:
  name - the name of the session attribute
Parameters:
  clazz - the class to instantiate for a new attribute the value of the session attribute, newly created if not found
throws:
  IllegalArgumentException - if the session attribute could not be instantiated



getParametersStartingWith
public static Map getParametersStartingWith(ServletRequest request, String prefix)(Code)
Return a map containing all parameters with the given prefix. Maps single values to String and multiple values to String array.

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.
Parameters:
  request - HTTP request in which to look for parameters
Parameters:
  prefix - the beginning of parameter names(if this is null or the empty string, all parameters will match) map containing request parameters without the prefix,containing either a String or a String array as values
See Also:   javax.servlet.ServletRequest.getParameterNames
See Also:   javax.servlet.ServletRequest.getParameterValues
See Also:   javax.servlet.ServletRequest.getParameterMap




getRealPath
public static String getRealPath(ServletContext servletContext, String path) throws FileNotFoundException(Code)
Return the real path of the given path within the web application, as provided by the servlet container.

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).
Parameters:
  servletContext - the servlet context of the web application
Parameters:
  path - the path within the web application the corresponding real path
throws:
  FileNotFoundException - if the path cannot be resolved to a resource
See Also:   javax.servlet.ServletContext.getRealPath




getRequiredSessionAttribute
public static Object getRequiredSessionAttribute(HttpServletRequest request, String name) throws IllegalStateException(Code)
Check the given request for a session attribute of the given name. Throws an exception if there is no session or if the session has no such attribute. Does not create a new session if none has existed before!
Parameters:
  request - current HTTP request
Parameters:
  name - the name of the session attribute the value of the session attribute, or null if not found
throws:
  IllegalStateException - if the session attribute could not be found



getSessionAttribute
public static Object getSessionAttribute(HttpServletRequest request, String name)(Code)
Check the given request for a session attribute of the given name. Returns null if there is no session or if the session has no such attribute. Does not create a new session if none has existed before!
Parameters:
  request - current HTTP request
Parameters:
  name - the name of the session attribute the value of the session attribute, or null if not found



getSessionId
public static String getSessionId(HttpServletRequest request)(Code)
Determine the session id of the given request, if any.
Parameters:
  request - current HTTP request the session id, or null if none



getSessionMutex
public static Object getSessionMutex(HttpSession session)(Code)
Return the best available mutex for the given session: that is, an object to synchronize on for the given 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.
Parameters:
  session - the HttpSession to find a mutex for the mutex object (never null)
See Also:   WebUtils.SESSION_MUTEX_ATTRIBUTE
See Also:   HttpSessionMutexListener




getTempDir
public static File getTempDir(ServletContext servletContext)(Code)
Return the temporary directory for the current web application, as provided by the servlet container.
Parameters:
  servletContext - the servlet context of the web application the File representing the temporary directory



hasSubmitParameter
public static boolean hasSubmitParameter(ServletRequest request, String name)(Code)
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").
Parameters:
  request - current HTTP request
Parameters:
  name - name of the parameter if the parameter was sent
See Also:   WebUtils.SUBMIT_IMAGE_SUFFIXES



isDefaultHtmlEscape
public static boolean isDefaultHtmlEscape(ServletContext servletContext)(Code)
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).
Parameters:
  servletContext - the servlet context of the web application whether default HTML escaping is enabled (default is false)



isIncludeRequest
public static boolean isIncludeRequest(ServletRequest request)(Code)
Determine whether the given request is an include request, that is, not a top-level HTTP request coming in from the outside.

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.
Parameters:
  request - current servlet request whether the given request is an include request




removeWebAppRootSystemProperty
public static void removeWebAppRootSystemProperty(ServletContext servletContext)(Code)
Remove the system property that points to the web app root directory. To be called on shutdown of the web application.
Parameters:
  servletContext - the servlet context of the web application
See Also:   WebUtils.setWebAppRootSystemProperty



setSessionAttribute
public static void setSessionAttribute(HttpServletRequest request, String name, Object value)(Code)
Set the session attribute with the given name to the given value. Removes the session attribute if value is null, if a session existed at all. Does not create a new session if not necessary!
Parameters:
  request - current HTTP request
Parameters:
  name - the name of the session attribute
Parameters:
  value - the value of the session attribute



setWebAppRootSystemProperty
public static void setWebAppRootSystemProperty(ServletContext servletContext) throws IllegalStateException(Code)
Set a system property to the web application root directory. The key of the system property can be defined with the "webAppRootKey" context-param in 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.
Parameters:
  servletContext - the servlet context of the web application
throws:
  IllegalStateException - if the system property is already set,or if the WAR file is not expanded
See Also:   WebUtils.WEB_APP_ROOT_KEY_PARAM
See Also:   WebUtils.DEFAULT_WEB_APP_ROOT_KEY
See Also:   WebAppRootListener
See Also:   Log4jWebConfigurer




Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.