public final class GeneralServletTools
extends java.lang.Object
Constructor and Description |
---|
GeneralServletTools() |
Modifier and Type | Method and Description |
---|---|
static java.lang.String |
getAbsolutePath(java.lang.String fname,
javax.servlet.ServletContext servletContext)
Gets the absolute path to a given file or directory.
|
static java.lang.String |
getAbsolutePath(java.lang.String fname,
java.lang.String docRoot)
Gets the absolute path to a given file or directory.
|
static java.lang.String |
getContextPath(javax.servlet.ServletContext servletContext)
Returns the context path for the webapp, for example '/dds' or '/' for the root context.
|
static java.lang.String |
getContextUrl(javax.servlet.http.HttpServletRequest req)
Gets the URL that refers to the current server and servlet context, for example
"http://www.dlese.org/dds" or "http://domain.org:8080/context" or or "http://localhost:8080/context".
|
static java.lang.String |
getQueryString(javax.servlet.http.HttpServletRequest request)
Gets the query string supplied in the request, for example "q=ocean&s=0&n=10".
|
static java.lang.String |
getRequestURI(javax.servlet.http.HttpServletRequest req)
Returns the part of this request's URL from the protocol name up to the query string in the first line of
the HTTP request.
|
static java.lang.StringBuffer |
getRequestURL(javax.servlet.http.HttpServletRequest req)
Reconstructs the URL the client used to make the request, even if the page has been forwarded for example
via struts (action.do).
|
static java.lang.String |
getServerUrl(javax.servlet.http.HttpServletRequest req)
Gets the URL that refers to the current server (scheme, hostname and port), for example
"http://www.dlese.org" or "http://host:8080" or "http://localhost:8080".
|
public static java.lang.String getContextPath(javax.servlet.ServletContext servletContext)
servletContext
- The ServletContext object for the webapppublic static java.lang.String getServerUrl(javax.servlet.http.HttpServletRequest req)
req
- The request.public static java.lang.String getContextUrl(javax.servlet.http.HttpServletRequest req)
req
- The request.public static java.lang.String getQueryString(javax.servlet.http.HttpServletRequest request)
HttpServletRequest.getQueryString()
, but works even if the request has been
forwarded.request
- The requestpublic static java.lang.StringBuffer getRequestURL(javax.servlet.http.HttpServletRequest req)
req
- The request.public static java.lang.String getRequestURI(javax.servlet.http.HttpServletRequest req)
req
- The request.public static final java.lang.String getAbsolutePath(java.lang.String fname, javax.servlet.ServletContext servletContext) throws javax.servlet.ServletException
If the string that is passed in already begings with "/", nothing is done.
Note: the HttpServlet init() (super.init()) method must be called prior to using this method, else a ServletException is thrown.
fname
- An absolute or relative file name or path (relative the the context root).servletContext
- The HttpServletContext of the appliection.javax.servlet.ServletException
- An exception related to this servletpublic static final java.lang.String getAbsolutePath(java.lang.String fname, java.lang.String docRoot)
If the string that is passed in already begings with "/", nothing is done.
Note: the super.init() method must be called prior to using this method, else a ServletException is thrown.
fname
- An absolute or relative file name or path (relative the the context root).docRoot
- The context document root as obtained by calling getServletContext().getRealPath("/");