All Packages Class Hierarchy This Package Previous Next Index
Class com.oreilly.servlet.ServletUtils
java.lang.Object
|
+----com.oreilly.servlet.ServletUtils
- public class ServletUtils
- extends Object
A collection of static utility methods useful to servlets.
Some methods require Servlet API 2.2.
- Version:
- 1.4, 2000/09/27, finalized getResource() behavior
- Author:
- Jason Hunter, Copyright © 1998-2000
-
ServletUtils()
-
-
getResource(ServletContext, String)
- 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.
-
getServlet(String, ServletRequest, ServletContext)
- Gets a reference to the named servlet, attempting to load it
through an HTTP request if necessary.
-
getStackTraceAsString(Throwable)
- Gets an exception's stack trace as a String
-
returnFile(String, OutputStream)
- Sends the contents of the specified file to the output stream
-
returnURL(URL, OutputStream)
- Sends the contents of the specified URL to the output stream
-
returnURL(URL, PrintWriter)
- Sends the contents of the specified URL to the PrintWriter
-
split(String, String)
- Splits a String into pieces according to a delimiter.
ServletUtils
public ServletUtils()
returnFile
public static void returnFile(String filename,
OutputStream out) throws FileNotFoundException, IOException
- Sends the contents of the specified file to the output stream
- Parameters:
- filename - the file to send
- out - the output stream to write the file
- Throws: FileNotFoundException
- if the file does not exist
- Throws: IOException
- if an I/O error occurs
returnURL
public static void returnURL(URL url,
OutputStream out) throws IOException
- Sends the contents of the specified URL to the output stream
- Parameters:
- URL - whose contents are to be sent
- out - the output stream to write the contents
- Throws: IOException
- if an I/O error occurs
returnURL
public static void returnURL(URL url,
PrintWriter out) throws IOException
- Sends the contents of the specified URL to the PrintWriter
- Parameters:
- URL - whose contents are to be sent
- out - the PrintWriter to write the contents
- Throws: IOException
- if an I/O error occurs
getStackTraceAsString
public static String getStackTraceAsString(Throwable t)
- Gets an exception's stack trace as a String
- Parameters:
- e - the exception
- Returns:
- the stack trace of the exception
getServlet
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. 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
- req - the servlet request
- context - the servlet context
- Returns:
- the named servlet, or null if there was a problem
split
public static String[] split(String str,
String delim)
- Splits a String into pieces according to a delimiter.
- Parameters:
- str - the string to split
- delim - the delimiter
- Returns:
- an array of strings containing the pieces
getResource
public static URL getResource(ServletContext context,
String resource) throws IOException
- 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
- resource - the resource to be read
- Returns:
- a URL reference to the resource
- Throws: IOException
- if there's any problem accessing the resource
All Packages Class Hierarchy This Package Previous Next Index