java.lang.Object
com.aoapps.servlet.http.HttpServletUtil
Static utilities that may be useful by servlet/JSP/taglib environments.
- Author:
- AO Industries, Inc.
- See Also:
-
Nested Class Summary
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic String
buildRedirectURL
(HttpServletRequest request, HttpServletResponse response, String href, URIParameters params, boolean absolute, boolean canonical) static String
buildRedirectURL
(HttpServletRequest request, HttpServletResponse response, String href, URIParameters params, HttpServletUtil.UrlModifier modifier, boolean absolute, boolean canonical) Builds a URL that should be used for a redirect location, with path resolved relative to the given request.static String
buildRedirectURL
(HttpServletRequest request, HttpServletResponse response, String servletPath, String href, URIParameters params, boolean absolute, boolean canonical) static String
buildRedirectURL
(HttpServletRequest request, HttpServletResponse response, String servletPath, String href, URIParameters params, HttpServletUtil.UrlModifier modifier, boolean absolute, boolean canonical) Builds a URL that should be used for a redirect location, including all the proper URL conversions.static String
buildRedirectURL
(JspContext jspContext, String href, URIParameters params, boolean absolute, boolean canonical) static String
buildRedirectURL
(JspContext jspContext, String href, URIParameters params, HttpServletUtil.UrlModifier modifier, boolean absolute, boolean canonical) static String
buildRedirectURL
(PageContext pageContext, String href, URIParameters params, boolean absolute, boolean canonical) static String
buildRedirectURL
(PageContext pageContext, String href, URIParameters params, HttpServletUtil.UrlModifier modifier, boolean absolute, boolean canonical) static String
buildURL
(HttpServletRequest request, HttpServletResponse response, String url, URIParameters params, boolean absolute, boolean canonical) static String
buildURL
(HttpServletRequest request, HttpServletResponse response, String url, URIParameters params, HttpServletUtil.UrlModifier modifier, boolean absolute, boolean canonical) Builds a URL with path resolved relative to the given request.static String
buildURL
(HttpServletRequest request, HttpServletResponse response, String servletPath, String url, URIParameters params, boolean absolute, boolean canonical) static String
buildURL
(HttpServletRequest request, HttpServletResponse response, String servletPath, String url, URIParameters params, HttpServletUtil.UrlModifier modifier, boolean absolute, boolean canonical) Builds a URL with all the proper URL conversions.static String
buildURL
(JspContext jspContext, String url, URIParameters params, boolean absolute, boolean canonical) static String
buildURL
(JspContext jspContext, String url, URIParameters params, HttpServletUtil.UrlModifier modifier, boolean absolute, boolean canonical) static String
buildURL
(PageContext pageContext, String url, URIParameters params, boolean absolute, boolean canonical) static String
buildURL
(PageContext pageContext, String url, URIParameters params, HttpServletUtil.UrlModifier modifier, boolean absolute, boolean canonical) static <S extends HttpServlet>
voiddoOptions
(HttpServletResponse response, Class<S> stopClass, Class<? extends S> thisClass, String doGet, String doPost, String doPut, String doDelete, Class<?>[] paramTypes) A reusable doOptions implementation for servlets.static String
getAbsolutePath
(HttpServletRequest request, String path) Resolves a possibly page-relative path to a context-absolute path.static String
getAbsoluteURL
(HttpServletRequest request, boolean contextRelative, String path) Gets an absolute URL for the given path.static void
getAbsoluteURL
(HttpServletRequest request, boolean contextRelative, String path, Encoder encoder, Appendable out) Gets an absolute URL for the given path.static void
getAbsoluteURL
(HttpServletRequest request, boolean contextRelative, String path, Appendable out) Gets an absolute URL for the given path.static String
getAbsoluteURL
(HttpServletRequest request, String path) Gets an absolute URL for the given path.static String
getAbsoluteURL
(HttpServletRequest request, String path, boolean contextRelative) Deprecated.static void
getAbsoluteURL
(HttpServletRequest request, String path, boolean contextRelative, Encoder encoder, Appendable out) static void
getAbsoluteURL
(HttpServletRequest request, String path, boolean contextRelative, Appendable out) Deprecated.static void
getAbsoluteURL
(HttpServletRequest request, String path, Encoder encoder, Appendable out) Gets an absolute URL for the given path.static void
getAbsoluteURL
(HttpServletRequest request, String path, Appendable out) Gets an absolute URL for the given path.static Method[]
getAllDeclaredMethods
(Class<?> stopClass, Class<?> c) static String
getContextRequestUri
(HttpServletRequest request) Gets the current request URI in context-absolute form.static String
getSubmittedFileName
(Part part) Gets the submitted filename for a file upload ornull
when unknown.static boolean
isGooglebot
(HttpServletRequest request) Determines if the requestor is Googlebot as described at: http://www.google.com/support/webmasters/bin/answer.py?static void
sendRedirect
(int status, HttpServletRequest request, HttpServletResponse response, String href, URIParameters params, boolean absolute, boolean canonical) static void
sendRedirect
(int status, HttpServletRequest request, HttpServletResponse response, String href, URIParameters params, HttpServletUtil.UrlModifier modifier, boolean absolute, boolean canonical) static void
sendRedirect
(int status, HttpServletRequest request, HttpServletResponse response, String servletPath, String href, URIParameters params, boolean absolute, boolean canonical) static void
sendRedirect
(int status, HttpServletRequest request, HttpServletResponse response, String servletPath, String href, URIParameters params, HttpServletUtil.UrlModifier modifier, boolean absolute, boolean canonical) static void
sendRedirect
(int status, HttpServletResponse response, String location) Sends a redirect to the provided location.static void
sendRedirect
(int status, JspContext jspContext, String href, URIParameters params, boolean absolute, boolean canonical) static void
sendRedirect
(int status, JspContext jspContext, String href, URIParameters params, HttpServletUtil.UrlModifier modifier, boolean absolute, boolean canonical) static void
sendRedirect
(int status, PageContext pageContext, String href, URIParameters params, boolean absolute, boolean canonical) static void
sendRedirect
(int status, PageContext pageContext, String href, URIParameters params, HttpServletUtil.UrlModifier modifier, boolean absolute, boolean canonical)
-
Field Details
-
METHOD_DELETE
- See Also:
-
METHOD_HEAD
- See Also:
-
METHOD_GET
- See Also:
-
METHOD_OPTIONS
- See Also:
-
METHOD_POST
- See Also:
-
METHOD_PUT
- See Also:
-
METHOD_TRACE
- See Also:
-
-
Method Details
-
isGooglebot
Determines if the requestor is Googlebot as described at: http://www.google.com/support/webmasters/bin/answer.py?answer=80553 -
getAbsolutePath
public static String getAbsolutePath(HttpServletRequest request, String path) throws MalformedURLException Resolves a possibly page-relative path to a context-absolute path.- Parameters:
path
- The absolute URL, context-absolute path, or page-relative path- Throws:
MalformedURLException
- See Also:
-
getAbsoluteURL
public static String getAbsoluteURL(HttpServletRequest request, boolean contextRelative, String path) Gets an absolute URL for the given path. This includes protocol, port, context path (optional), and path. No URL rewriting is performed.- Parameters:
contextRelative
- Whentrue
, includesHttpServletRequest.getContextPath()
in the URL.path
- The path appended to the URL verbatim. To support page-relative paths, first usegetAbsolutePath(javax.servlet.http.HttpServletRequest, java.lang.String)
-
getAbsoluteURL
@Deprecated public static String getAbsoluteURL(HttpServletRequest request, String path, boolean contextRelative) Deprecated.Please usegetAbsoluteURL(javax.servlet.http.HttpServletRequest, boolean, java.lang.String)
instead. -
getAbsoluteURL
Gets an absolute URL for the given path. This includes protocol, port, context path, and path. No URL rewriting is performed.- Parameters:
path
- The path appended to the URL verbatim. To support page-relative paths, first usegetAbsolutePath(javax.servlet.http.HttpServletRequest, java.lang.String)
-
getAbsoluteURL
public static void getAbsoluteURL(HttpServletRequest request, boolean contextRelative, String path, Appendable out) throws IOException Gets an absolute URL for the given path. This includes protocol, port, context path (optional), and path. No URL rewriting is performed.- Parameters:
contextRelative
- Whentrue
, includesHttpServletRequest.getContextPath()
in the URL.path
- The path appended to the URL verbatim. To support page-relative paths, first usegetAbsolutePath(javax.servlet.http.HttpServletRequest, java.lang.String)
- Throws:
IOException
-
getAbsoluteURL
@Deprecated public static void getAbsoluteURL(HttpServletRequest request, String path, boolean contextRelative, Appendable out) throws IOException Deprecated.- Throws:
IOException
-
getAbsoluteURL
public static void getAbsoluteURL(HttpServletRequest request, String path, Appendable out) throws IOException Gets an absolute URL for the given path. This includes protocol, port, context path, and path. No URL rewriting is performed.- Parameters:
path
- The path appended to the URL verbatim. To support page-relative paths, first usegetAbsolutePath(javax.servlet.http.HttpServletRequest, java.lang.String)
- Throws:
IOException
-
getAbsoluteURL
public static void getAbsoluteURL(HttpServletRequest request, boolean contextRelative, String path, Encoder encoder, Appendable out) throws IOException Gets an absolute URL for the given path. This includes protocol, port, context path (optional), and path. No URL rewriting is performed.- Parameters:
contextRelative
- Whentrue
, includesHttpServletRequest.getContextPath()
in the URL.path
- The path appended to the URL verbatim. To support page-relative paths, first usegetAbsolutePath(javax.servlet.http.HttpServletRequest, java.lang.String)
- Throws:
IOException
-
getAbsoluteURL
@Deprecated public static void getAbsoluteURL(HttpServletRequest request, String path, boolean contextRelative, Encoder encoder, Appendable out) throws IOException Deprecated.- Throws:
IOException
-
getAbsoluteURL
public static void getAbsoluteURL(HttpServletRequest request, String path, Encoder encoder, Appendable out) throws IOException Gets an absolute URL for the given path. This includes protocol, port, context path, and path. No URL rewriting is performed.- Parameters:
path
- The path appended to the URL verbatim. To support page-relative paths, first usegetAbsolutePath(javax.servlet.http.HttpServletRequest, java.lang.String)
- Throws:
IOException
-
buildRedirectURL
public static String buildRedirectURL(HttpServletRequest request, HttpServletResponse response, String servletPath, String href, URIParameters params, HttpServletUtil.UrlModifier modifier, boolean absolute, boolean canonical) throws MalformedURLException Builds a URL that should be used for a redirect location, including all the proper URL conversions. This includes:- Converting a page-relative path to a context-absolute path starting with a slash (/), resolving ./ and ../
- Adding any additional parameters
- Optionally modifying the URL
- Encoding any URL path characters not defined in RFC 3986: Reserved Characters
- Converting any context-absolute path to a site-absolute path by prefixing contextPath
- Optionally convert to an absolute URL:
http[s]://…
- Rewrite with
HttpServletResponse.encodeRedirectURL(java.lang.String)
- Final US-ASCII encoding since Location must always be RFC 3986
- Parameters:
href
- The absolute URL, context-absolute path, or page-relative pathcanonical
- The value to use forCanonical
duringHttpServletResponse.encodeRedirectURL(java.lang.String)
- Throws:
MalformedURLException
- See Also:
-
buildRedirectURL
public static String buildRedirectURL(HttpServletRequest request, HttpServletResponse response, String servletPath, String href, URIParameters params, boolean absolute, boolean canonical) throws MalformedURLException - Throws:
MalformedURLException
- See Also:
-
buildRedirectURL
public static String buildRedirectURL(HttpServletRequest request, HttpServletResponse response, String href, URIParameters params, HttpServletUtil.UrlModifier modifier, boolean absolute, boolean canonical) throws MalformedURLException Builds a URL that should be used for a redirect location, with path resolved relative to the given request.- Throws:
MalformedURLException
- See Also:
-
buildRedirectURL
public static String buildRedirectURL(HttpServletRequest request, HttpServletResponse response, String href, URIParameters params, boolean absolute, boolean canonical) throws MalformedURLException - Throws:
MalformedURLException
- See Also:
-
buildRedirectURL
public static String buildRedirectURL(PageContext pageContext, String href, URIParameters params, HttpServletUtil.UrlModifier modifier, boolean absolute, boolean canonical) throws MalformedURLException - Throws:
MalformedURLException
- See Also:
-
buildRedirectURL
public static String buildRedirectURL(PageContext pageContext, String href, URIParameters params, boolean absolute, boolean canonical) throws MalformedURLException - Throws:
MalformedURLException
- See Also:
-
buildRedirectURL
public static String buildRedirectURL(JspContext jspContext, String href, URIParameters params, HttpServletUtil.UrlModifier modifier, boolean absolute, boolean canonical) throws MalformedURLException - Throws:
MalformedURLException
- See Also:
-
buildRedirectURL
public static String buildRedirectURL(JspContext jspContext, String href, URIParameters params, boolean absolute, boolean canonical) throws MalformedURLException - Throws:
MalformedURLException
- See Also:
-
buildURL
public static String buildURL(HttpServletRequest request, HttpServletResponse response, String servletPath, String url, URIParameters params, HttpServletUtil.UrlModifier modifier, boolean absolute, boolean canonical) throws MalformedURLException Builds a URL with all the proper URL conversions. This includes:- Converting a page-relative path to a context-absolute path starting with a slash (/), resolving ./ and ../
- Adding any additional parameters
- Optionally modifying the URL
- Encoding any URL path characters not defined in RFC 3986: Reserved Characters
- Converting any context-absolute path to a site-absolute path by prefixing contextPath
- Optionally convert to an absolute URL:
http[s]://…
- Rewrite with
HttpServletResponse.encodeURL(java.lang.String)
- Parameters:
url
- The absolute URL, context-absolute path, or page-relative pathcanonical
- The value to use forCanonical
duringHttpServletResponse.encodeURL(java.lang.String)
- Throws:
MalformedURLException
-
buildURL
public static String buildURL(HttpServletRequest request, HttpServletResponse response, String servletPath, String url, URIParameters params, boolean absolute, boolean canonical) throws MalformedURLException - Throws:
MalformedURLException
- See Also:
-
buildURL
public static String buildURL(HttpServletRequest request, HttpServletResponse response, String url, URIParameters params, HttpServletUtil.UrlModifier modifier, boolean absolute, boolean canonical) throws MalformedURLException Builds a URL with path resolved relative to the given request.- Throws:
MalformedURLException
- See Also:
-
buildURL
public static String buildURL(HttpServletRequest request, HttpServletResponse response, String url, URIParameters params, boolean absolute, boolean canonical) throws MalformedURLException - Throws:
MalformedURLException
- See Also:
-
buildURL
public static String buildURL(PageContext pageContext, String url, URIParameters params, HttpServletUtil.UrlModifier modifier, boolean absolute, boolean canonical) throws MalformedURLException - Throws:
MalformedURLException
- See Also:
-
buildURL
public static String buildURL(PageContext pageContext, String url, URIParameters params, boolean absolute, boolean canonical) throws MalformedURLException - Throws:
MalformedURLException
- See Also:
-
buildURL
public static String buildURL(JspContext jspContext, String url, URIParameters params, HttpServletUtil.UrlModifier modifier, boolean absolute, boolean canonical) throws MalformedURLException - Throws:
MalformedURLException
- See Also:
-
buildURL
public static String buildURL(JspContext jspContext, String url, URIParameters params, boolean absolute, boolean canonical) throws MalformedURLException - Throws:
MalformedURLException
- See Also:
-
sendRedirect
public static void sendRedirect(int status, HttpServletResponse response, String location) throws IllegalStateException, IOException Sends a redirect to the provided location. Encodes the location to US-ASCII format. Response must not be committed.- Throws:
IllegalStateException
- when the response is already committedIOException
- See Also:
-
sendRedirect
public static void sendRedirect(int status, HttpServletRequest request, HttpServletResponse response, String servletPath, String href, URIParameters params, HttpServletUtil.UrlModifier modifier, boolean absolute, boolean canonical) throws MalformedURLException, IllegalStateException, IOException - Throws:
IllegalStateException
- when the response is already committedMalformedURLException
IOException
- See Also:
-
sendRedirect
public static void sendRedirect(int status, HttpServletRequest request, HttpServletResponse response, String servletPath, String href, URIParameters params, boolean absolute, boolean canonical) throws MalformedURLException, IllegalStateException, IOException - Throws:
MalformedURLException
IllegalStateException
IOException
- See Also:
-
sendRedirect
public static void sendRedirect(int status, HttpServletRequest request, HttpServletResponse response, String href, URIParameters params, HttpServletUtil.UrlModifier modifier, boolean absolute, boolean canonical) throws MalformedURLException, IllegalStateException, IOException - Throws:
IllegalStateException
- when the response is already committedMalformedURLException
IOException
- See Also:
-
sendRedirect
public static void sendRedirect(int status, HttpServletRequest request, HttpServletResponse response, String href, URIParameters params, boolean absolute, boolean canonical) throws MalformedURLException, IllegalStateException, IOException - Throws:
MalformedURLException
IllegalStateException
IOException
- See Also:
-
sendRedirect
public static void sendRedirect(int status, PageContext pageContext, String href, URIParameters params, HttpServletUtil.UrlModifier modifier, boolean absolute, boolean canonical) throws MalformedURLException, IllegalStateException, IOException - Throws:
IllegalStateException
- when the response is already committedMalformedURLException
IOException
- See Also:
-
sendRedirect
public static void sendRedirect(int status, PageContext pageContext, String href, URIParameters params, boolean absolute, boolean canonical) throws MalformedURLException, IllegalStateException, IOException - Throws:
MalformedURLException
IllegalStateException
IOException
- See Also:
-
sendRedirect
public static void sendRedirect(int status, JspContext jspContext, String href, URIParameters params, HttpServletUtil.UrlModifier modifier, boolean absolute, boolean canonical) throws MalformedURLException, IllegalStateException, IOException - Throws:
IllegalStateException
- when the response is already committedMalformedURLException
IOException
- See Also:
-
sendRedirect
public static void sendRedirect(int status, JspContext jspContext, String href, URIParameters params, boolean absolute, boolean canonical) throws MalformedURLException, IllegalStateException, IOException - Throws:
MalformedURLException
IllegalStateException
IOException
- See Also:
-
getContextRequestUri
Gets the current request URI in context-absolute form. The contextPath stripped. -
getAllDeclaredMethods
-
doOptions
public static <S extends HttpServlet> void doOptions(HttpServletResponse response, Class<S> stopClass, Class<? extends S> thisClass, String doGet, String doPost, String doPut, String doDelete, Class<?>[] paramTypes) A reusable doOptions implementation for servlets. -
getSubmittedFileName
Gets the submitted filename for a file upload ornull
when unknown. In addition to the default implementation ofPart.getSubmittedFileName()
, also:- Applies a MSIE fix
- Protects against '/' or NULL characters, since servers have POSIX filesystem
- Returns
null
and never empty string (servlet spec is not clear here)
- See Also:
-
getAbsoluteURL(javax.servlet.http.HttpServletRequest, boolean, java.lang.String)
instead.