| java.lang.Object com.oreilly.servlet.ServletUtils
ServletUtils | public class ServletUtils (Code) | | A collection of static utility methods useful to servlets.
Some methods require Servlet API 2.2.
author: Jason Hunter, Copyright © 1998-2000 version: 1.5, 2001/02/11, added getResource() ".." check version: 1.4, 2000/09/27, finalized getResource() behavior version: 1.3, 2000/08/15, improved getStackTraceAsString() to take Throwable version: 1.2, 2000/03/10, added getResource() method version: 1.1, 2000/02/13, added returnURL() methods version: 1.0, 1098/09/18 |
Method Summary | |
public 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. | public 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. | public static String | getStackTraceAsString(Throwable t) | public static void | returnFile(String filename, OutputStream out) | public static void | returnURL(URL url, OutputStream out) | public static void | returnURL(URL url, Writer out) |
getResource | public static URL getResource(ServletContext context, String resource) throws IOException(Code) | | 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.
Throws an IOException if the resource can't be read.
Parameters: context - the context containing the resource Parameters: resource - the resource to be read a URL reference to the resource exception: IOException - if there's any problem accessing the resource |
getServlet | public static Servlet getServlet(String name, ServletRequest req, ServletContext context)(Code) | | Gets a reference to the named servlet, attempting to load it
through an HTTP request if necessary. Returns null if there's a problem.
This method behaves similarly to ServletContext.getServlet()
except, while that method may return null if the
named servlet wasn't already loaded, this method tries to load
the servlet using a dummy HTTP request. Only loads HTTP servlets.
Parameters: name - the name of the servlet Parameters: req - the servlet request Parameters: context - the servlet context the named servlet, or null if there was a problem |
getStackTraceAsString | public static String getStackTraceAsString(Throwable t)(Code) | | Gets an exception's stack trace as a String
Parameters: e - the exception the stack trace of the exception |
returnURL | public static void returnURL(URL url, OutputStream out) throws IOException(Code) | | Sends the contents of the specified URL to the output stream
Parameters: URL - whose contents are to be sent Parameters: out - the output stream to write the contents exception: IOException - if an I/O error occurs |
returnURL | public static void returnURL(URL url, Writer out) throws IOException(Code) | | Sends the contents of the specified URL to the Writer (commonly either a
PrintWriter or JspWriter)
Parameters: URL - whose contents are to be sent Parameters: out - the Writer to write the contents exception: IOException - if an I/O error occurs |
|
|