Home
What's
New?
com.oreilly.servlet
Servlet
Polls
Mailing
Lists
List
Archives
Servlet
Engines
Servlet
ISPs
Servlet
Tools
Documentation
Online
Articles
The
Soapbox
"Java
Servlet
Programming,
Second Edition"
"Java
Enterprise
Best Practices"
Speaking
& Slides
About
Jason
XQuery
Affiliate
Advertising
Info
|
com.oreilly.servlet
Class ServletUtils
java.lang.Object
|
+--com.oreilly.servlet.ServletUtils
- public class ServletUtils
- extends java.lang.Object
A collection of static utility methods useful to servlets.
Some methods require Servlet API 2.2.
- Version:
- 1.5, 2001/02/11, added getResource() ".." check
, 1.4, 2000/09/27, finalized getResource() behavior
, 1.3, 2000/08/15, improved getStackTraceAsString() to take Throwable
, 1.2, 2000/03/10, added getResource() method
, 1.1, 2000/02/13, added returnURL() methods
, 1.0, 1098/09/18
- Author:
- Jason Hunter, Copyright © 1998-2000
|
Method Summary |
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. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ServletUtils
public ServletUtils()
returnFile
public static void returnFile(java.lang.String filename,
java.io.OutputStream out)
throws java.io.FileNotFoundException,
java.io.IOException
- Sends the contents of the specified file to the output stream
- Parameters:
filename - the file to sendout - the output stream to write the file
- Throws:
java.io.FileNotFoundException - if the file does not exist
java.io.IOException - if an I/O error occurs
returnURL
public static void returnURL(java.net.URL url,
java.io.OutputStream out)
throws java.io.IOException
- Sends the contents of the specified URL to the output stream
- Parameters:
out - the output stream to write the contents
- Throws:
java.io.IOException - if an I/O error occurs
returnURL
public static void returnURL(java.net.URL url,
java.io.Writer out)
throws java.io.IOException
- Sends the contents of the specified URL to the Writer (commonly either a
PrintWriter or JspWriter)
- Parameters:
out - the Writer to write the contents
- Throws:
java.io.IOException - if an I/O error occurs
getStackTraceAsString
public static java.lang.String getStackTraceAsString(java.lang.Throwable t)
- Gets an exception's stack trace as a String
- Returns:
- the stack trace of the exception
getServlet
public 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. 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 servletreq - the servlet requestcontext - the servlet context
- Returns:
- the named servlet, or null if there was a problem
split
public static java.lang.String[] split(java.lang.String str,
java.lang.String delim)
- Splits a String into pieces according to a delimiter.
- Parameters:
str - the string to splitdelim - the delimiter
- Returns:
- an array of strings containing the pieces
getResource
public static java.net.URL getResource(javax.servlet.ServletContext context,
java.lang.String resource)
throws java.io.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 resourceresource - the resource to be read
- Returns:
- a URL reference to the resource
- Throws:
java.io.IOException - if there's any problem accessing the resource
|