public class ServletUtils extends Object
Constructor and Description |
---|
ServletUtils() |
Modifier and Type | Method and Description |
---|---|
static URL |
getResource(ServletContext context,
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 Servlet |
getServlet(String name,
ServletRequest req,
ServletContext context)
Gets a reference to the named servlet, attempting to load it
through an HTTP request if necessary.
|
static String |
getStackTraceAsString(Throwable t)
Gets an exception's stack trace as a String
|
static void |
returnFile(String filename,
OutputStream out)
Sends the contents of the specified file to the output stream
|
static void |
returnURL(URL url,
OutputStream out)
Sends the contents of the specified URL to the output stream
|
static void |
returnURL(URL url,
Writer out)
Sends the contents of the specified URL to the Writer (commonly either a
PrintWriter or JspWriter)
|
static String[] |
split(String str,
String delim)
Splits a String into pieces according to a delimiter.
|
public ServletUtils()
public static void returnFile(String filename, OutputStream out) throws FileNotFoundException, IOException
filename
- the file to sendout
- the output stream to write the fileFileNotFoundException
- if the file does not existIOException
- if an I/O error occurspublic static void returnURL(URL url, OutputStream out) throws IOException
URL
- whose contents are to be sentout
- the output stream to write the contentsIOException
- if an I/O error occurspublic static void returnURL(URL url, Writer out) throws IOException
URL
- whose contents are to be sentout
- the Writer to write the contentsIOException
- if an I/O error occurspublic static String getStackTraceAsString(Throwable t)
e
- the exceptionpublic static Servlet getServlet(String name, ServletRequest req, ServletContext context)
name
- the name of the servletreq
- the servlet requestcontext
- the servlet contextpublic static String[] split(String str, String delim)
str
- the string to splitdelim
- the delimiterpublic static URL getResource(ServletContext context, String resource) throws IOException
context
- the context containing the resourceresource
- the resource to be readIOException
- if there's any problem accessing the resourceWebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses