public class ServletUtils extends Object
| 构造器和说明 |
|---|
ServletUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static URL |
getResource(javax.servlet.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 javax.servlet.Servlet |
getServlet(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 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 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)
t - the exception or throwable itempublic static javax.servlet.Servlet getServlet(String name, javax.servlet.ServletRequest req, javax.servlet.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(javax.servlet.ServletContext context, String resource) throws IOException
context - the context containing the resourceresource - the resource to be readIOException - if there's any problem accessing the resourceCopyright © 2022. All rights reserved.