public class ServletUtils
extends java.lang.Object
| Constructor and Description |
|---|
ServletUtils() |
| Modifier and Type | Method and Description |
|---|---|
static java.net.URL |
getResource(javax.servlet.ServletContext context,
java.lang.String resource)
Gets a reference to the given resource within the given context,
making sure not to serve the contents of WEB-INF, META-INF, or to
display .jsp file source.
|
static javax.servlet.Servlet |
getServlet(java.lang.String name,
javax.servlet.ServletRequest req,
javax.servlet.ServletContext context)
Gets a reference to the named servlet, attempting to load it
through an HTTP request if necessary.
|
static java.lang.String |
getStackTraceAsString(java.lang.Throwable t)
Gets an exception's stack trace as a String
|
static void |
returnFile(java.lang.String filename,
java.io.OutputStream out)
Sends the contents of the specified file to the output stream
|
static void |
returnURL(java.net.URL url,
java.io.OutputStream out)
Sends the contents of the specified URL to the output stream
|
static void |
returnURL(java.net.URL url,
java.io.Writer out)
Sends the contents of the specified URL to the Writer (commonly either a
PrintWriter or JspWriter)
|
static java.lang.String[] |
split(java.lang.String str,
java.lang.String delim)
Splits a String into pieces according to a delimiter.
|
public static void returnFile(java.lang.String filename,
java.io.OutputStream out)
throws java.io.FileNotFoundException,
java.io.IOException
filename - the file to sendout - the output stream to write the filejava.io.FileNotFoundException - if the file does not existjava.io.IOException - if an I/O error occurspublic static void returnURL(java.net.URL url,
java.io.OutputStream out)
throws java.io.IOException
url - whose contents are to be sentout - the output stream to write the contentsjava.io.IOException - if an I/O error occurspublic static void returnURL(java.net.URL url,
java.io.Writer out)
throws java.io.IOException
url - whose contents are to be sentout - the Writer to write the contentsjava.io.IOException - if an I/O error occurspublic static java.lang.String getStackTraceAsString(java.lang.Throwable t)
t - the exception or throwable itempublic static javax.servlet.Servlet getServlet(java.lang.String name,
javax.servlet.ServletRequest req,
javax.servlet.ServletContext context)
name - the name of the servletreq - the servlet requestcontext - the servlet contextpublic static java.lang.String[] split(java.lang.String str,
java.lang.String delim)
str - the string to splitdelim - the delimiterpublic static java.net.URL getResource(javax.servlet.ServletContext context,
java.lang.String resource)
throws java.io.IOException
context - the context containing the resourceresource - the resource to be readjava.io.IOException - if there's any problem accessing the resource