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.

版本:
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
作者:
Jason Hunter, Copyright © 1998-2000

构造方法摘要
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.
 
从类 java.lang.Object 继承的方法
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

构造方法详细信息

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

参数:
filename - the file to send
out - the output stream to write the file
抛出:
FileNotFoundException - if the file does not exist
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

参数:
url - whose contents are to be sent
out - the output stream to write the contents
抛出:
IOException - if an I/O error occurs

returnURL

public static void returnURL(URL url,
                             Writer out)
                      throws IOException
Sends the contents of the specified URL to the Writer (commonly either a PrintWriter or JspWriter)

参数:
url - whose contents are to be sent
out - the Writer to write the contents
抛出:
IOException - if an I/O error occurs

getStackTraceAsString

public static String getStackTraceAsString(Throwable t)
Gets an exception's stack trace as a String

参数:
t - the exception or throwable item
返回:
the stack trace of the exception

getServlet

public 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. 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.

参数:
name - the name of the servlet
req - the servlet request
context - the servlet context
返回:
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.

参数:
str - the string to split
delim - the delimiter
返回:
an array of strings containing the pieces

getResource

public static URL getResource(javax.servlet.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.

参数:
context - the context containing the resource
resource - the resource to be read
返回:
a URL reference to the resource
抛出:
IOException - if there's any problem accessing the resource


Copyright © 2013. All Rights Reserved.