home *** CD-ROM | disk | FTP | other *** search
/ PC World 2002 May / PCWorld_2002-05_cd.bin / Komunik / sambar / sambar51p.exe / lib / javaeng.jar / javax / servlet / ServletContext.java < prev    next >
Encoding:
Java Source  |  2001-10-22  |  20.8 KB  |  638 lines

  1. /*
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 1999 The Apache Software Foundation.  All rights 
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer. 
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution, if
  20.  *    any, must include the following acknowlegement:  
  21.  *       "This product includes software developed by the 
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowlegement may appear in the software itself,
  24.  *    if and wherever such third-party acknowlegements normally appear.
  25.  *
  26.  * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
  27.  *    Foundation" must not be used to endorse or promote products derived
  28.  *    from this software without prior written permission. For written 
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache"
  32.  *    nor may "Apache" appear in their names without prior written
  33.  *    permission of the Apache Group.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation.  For more
  51.  * information on the Apache Software Foundation, please see
  52.  * <http://www.apache.org/>.
  53.  *
  54.  * ====================================================================
  55.  *
  56.  * This source code implements specifications defined by the Java
  57.  * Community Process. In order to remain compliant with the specification
  58.  * DO NOT add / change / or delete method signatures!
  59.  */
  60.  
  61. package javax.servlet;
  62.  
  63. import java.io.InputStream;
  64. import java.io.IOException;
  65. import java.net.URL;
  66. import java.net.MalformedURLException;
  67. import java.util.Enumeration;
  68.  
  69.  
  70. /**
  71.  * 
  72.  * Defines a set of methods that a servlet uses to communicate with its
  73.  * servlet container, for example, to get the MIME type of a file, dispatch
  74.  * requests, or write to a log file.
  75.  *
  76.  * <p>There is one context per "web application" per Java Virtual Machine.  (A
  77.  * "web application" is a collection of servlets and content installed under a
  78.  * specific subset of the server's URL namespace such as <code>/catalog</code>
  79.  * and possibly installed via a <code>.war</code> file.) 
  80.  *
  81.  * <p>In the case of a web
  82.  * application marked "distributed" in its deployment descriptor, there will
  83.  * be one context instance for each virtual machine.  In this situation, the 
  84.  * context cannot be used as a location to share global information (because
  85.  * the information won't be truly global).  Use an external resource like 
  86.  * a database instead.
  87.  *
  88.  * <p>The <code>ServletContext</code> object is contained within 
  89.  * the {@link ServletConfig} object, which the Web server provides the
  90.  * servlet when the servlet is initialized.
  91.  *
  92.  * @author     Various
  93.  * @version     $Version$
  94.  *
  95.  * @see     Servlet#getServletConfig
  96.  * @see     ServletConfig#getServletContext
  97.  *
  98.  */
  99.  
  100. public interface ServletContext {
  101.  
  102.  
  103.     /**
  104.      * Returns a <code>ServletContext</code> object that 
  105.      * corresponds to a specified URL on the server.
  106.      *
  107.      * <p>This method allows servlets to gain
  108.      * access to the context for various parts of the server, and as
  109.      * needed obtain {@link RequestDispatcher} objects from the context.
  110.      * The given path must be absolute (beginning with "/") and is 
  111.      * interpreted based on the server's document root. 
  112.      * 
  113.      * <p>In a security conscious environment, the servlet container may
  114.      * return <code>null</code> for a given URL.
  115.      *       
  116.      * @param uripath     a <code>String</code> specifying the absolute URL of 
  117.      *            a resource on the server
  118.      *
  119.      * @return        the <code>ServletContext</code> object that
  120.      *            corresponds to the named URL
  121.      *
  122.      * @see         RequestDispatcher
  123.      *
  124.      */
  125.  
  126.     public ServletContext getContext(String uripath);
  127.     
  128.     
  129.  
  130.     /**
  131.      * Returns the major version of the Java Servlet API that this
  132.      * servlet container supports. All implementations that comply
  133.      * with Version 2.2 must have this method
  134.      * return the integer 2.
  135.      *
  136.      * @return         2
  137.      *
  138.      */
  139.     
  140.     public int getMajorVersion();
  141.     
  142.     
  143.  
  144.     /**
  145.      * Returns the minor version of the Servlet API that this
  146.      * servlet container supports. All implementations that comply
  147.      * with Version 2.2 must have this method
  148.      * return the integer 2.
  149.      *
  150.      * @return         2
  151.      *
  152.      */
  153.  
  154.     public int getMinorVersion();
  155.     
  156.     
  157.  
  158.     /**
  159.      * Returns the MIME type of the specified file, or <code>null</code> if 
  160.      * the MIME type is not known. The MIME type is determined
  161.      * by the configuration of the servlet container, and may be specified
  162.      * in a web application deployment descriptor. Common MIME
  163.      * types are <code>"text/html"</code> and <code>"image/gif"</code>.
  164.      *
  165.      *
  166.      * @param   file    a <code>String</code> specifying the name
  167.      *            of a file
  168.      *
  169.      * @return         a <code>String</code> specifying the file's MIME type
  170.      *
  171.      */
  172.  
  173.     public String getMimeType(String file);
  174.     
  175.     
  176.  
  177.     /**
  178.      * Returns a URL to the resource that is mapped to a specified
  179.      * path. The path must begin with a "/" and is interpreted
  180.      * as relative to the current context root.
  181.      *
  182.      * <p>This method allows the servlet container to make a resource 
  183.      * available to servlets from any source. Resources 
  184.      * can be located on a local or remote
  185.      * file system, in a database, or in a <code>.war</code> file. 
  186.      *
  187.      * <p>The servlet container must implement the URL handlers
  188.      * and <code>URLConnection</code> objects that are necessary
  189.      * to access the resource.
  190.      *
  191.      * <p>This method returns <code>null</code>
  192.      * if no resource is mapped to the pathname.
  193.      *
  194.      * <p>Some containers may allow writing to the URL returned by
  195.      * this method using the methods of the URL class.
  196.      *
  197.      * <p>The resource content is returned directly, so be aware that 
  198.      * requesting a <code>.jsp</code> page returns the JSP source code.
  199.      * Use a <code>RequestDispatcher</code> instead to include results of 
  200.      * an execution.
  201.      *
  202.      * <p>This method has a different purpose than
  203.      * <code>java.lang.Class.getResource</code>,
  204.      * which looks up resources based on a class loader. This
  205.      * method does not use class loaders.
  206.      * 
  207.      * @param path                 a <code>String</code> specifying
  208.      *                        the path to the resource
  209.      *
  210.      * @return                     the resource located at the named path,
  211.      *                         or <code>null</code> if there is no resource
  212.      *                        at that path
  213.      *
  214.      * @exception MalformedURLException     if the pathname is not given in 
  215.      *                         the correct form
  216.      *
  217.      */
  218.     
  219.     public URL getResource(String path) throws MalformedURLException;
  220.     
  221.     
  222.  
  223.     /**
  224.      * Returns the resource located at the named path as
  225.      * an <code>InputStream</code> object.
  226.      *
  227.      * <p>The data in the <code>InputStream</code> can be 
  228.      * of any type or length. The path must be specified according
  229.      * to the rules given in <code>getResource</code>.
  230.      * This method returns <code>null</code> if no resource exists at
  231.      * the specified path. 
  232.      * 
  233.      * <p>Meta-information such as content length and content type
  234.      * that is available via <code>getResource</code>
  235.      * method is lost when using this method.
  236.      *
  237.      * <p>The servlet container must implement the URL handlers
  238.      * and <code>URLConnection</code> objects necessary to access
  239.      * the resource.
  240.      *
  241.      * <p>This method is different from 
  242.      * <code>java.lang.Class.getResourceAsStream</code>,
  243.      * which uses a class loader. This method allows servlet containers 
  244.      * to make a resource available
  245.      * to a servlet from any location, without using a class loader.
  246.      * 
  247.      *
  248.      * @param name     a <code>String</code> specifying the path
  249.      *            to the resource
  250.      *
  251.      * @return         the <code>InputStream</code> returned to the 
  252.      *            servlet, or <code>null</code> if no resource
  253.      *            exists at the specified path 
  254.      *
  255.      *
  256.      */
  257.  
  258.     public InputStream getResourceAsStream(String path);
  259.     
  260.  
  261.  
  262.  
  263.     /**
  264.      * 
  265.      * Returns a {@link RequestDispatcher} object that acts
  266.      * as a wrapper for the resource located at the given path.
  267.      * A <code>RequestDispatcher</code> object can be used to forward 
  268.      * a request to the resource or to include the resource in a response.
  269.      * The resource can be dynamic or static.
  270.      *
  271.      * <p>The pathname must begin with a "/" and is interpreted as relative
  272.      * to the current context root.  Use <code>getContext</code> to obtain
  273.      * a <code>RequestDispatcher</code> for resources in foreign contexts.
  274.      * This method returns <code>null</code> if the <code>ServletContext</code>
  275.      * cannot return a <code>RequestDispatcher</code>.
  276.      *
  277.      * @param path     a <code>String</code> specifying the pathname
  278.      *            to the resource
  279.      *
  280.      * @return         a <code>RequestDispatcher</code> object
  281.      *            that acts as a wrapper for the resource
  282.      *            at the specified path
  283.      *
  284.      * @see         RequestDispatcher
  285.      * @see         ServletContext#getContext
  286.      *
  287.      */
  288.  
  289.     public RequestDispatcher getRequestDispatcher(String path);
  290.  
  291.  
  292.  
  293.     /**
  294.      * Returns a {@link RequestDispatcher} object that acts
  295.      * as a wrapper for the named servlet.
  296.      *
  297.      * <p>Servlets (and JSP pages also) may be given names via server 
  298.      * administration or via a web application deployment descriptor.
  299.      * A servlet instance can determine its name using 
  300.      * {@link ServletConfig#getServletName}.
  301.      *
  302.      * <p>This method returns <code>null</code> if the 
  303.      * <code>ServletContext</code>
  304.      * cannot return a <code>RequestDispatcher</code> for any reason.
  305.      *
  306.      * @param name     a <code>String</code> specifying the name
  307.      *            of a servlet to wrap
  308.      *
  309.      * @return         a <code>RequestDispatcher</code> object
  310.      *            that acts as a wrapper for the named servlet
  311.      *
  312.      * @see         RequestDispatcher
  313.      * @see         ServletContext#getContext
  314.      * @see         ServletConfig#getServletName
  315.      *
  316.      */
  317.  
  318.     public RequestDispatcher getNamedDispatcher(String name);
  319.     
  320.     
  321.     
  322.     
  323.     /**
  324.      *
  325.      * @deprecated    As of Java Servlet API 2.1, with no direct replacement.
  326.      *
  327.      * <p>This method was originally defined to retrieve a servlet
  328.      * from a <code>ServletContext</code>. In this version, this method 
  329.      * always returns <code>null</code> and remains only to preserve 
  330.      * binary compatibility. This method will be permanently removed 
  331.      * in a future version of the Java Servlet API.
  332.      *
  333.      * <p>In lieu of this method, servlets can share information using the 
  334.      * <code>ServletContext</code> class and can perform shared business logic
  335.      * by invoking methods on common non-servlet classes.
  336.      *
  337.      */
  338.  
  339.     public Servlet getServlet(String name) throws ServletException;
  340.     
  341.   
  342.   
  343.   
  344.     
  345.  
  346.     /**
  347.      *
  348.      * @deprecated    As of Java Servlet API 2.0, with no replacement.
  349.      *
  350.      * <p>This method was originally defined to return an <code>Enumeration</code>
  351.      * of all the servlets known to this servlet context. In this
  352.      * version, this method always returns an empty enumeration and
  353.      * remains only to preserve binary compatibility. This method
  354.      * will be permanently removed in a future version of the Java
  355.      * Servlet API.
  356.      *
  357.      */
  358.     
  359.     public Enumeration getServlets();
  360.     
  361.     
  362.     
  363.     
  364.     
  365.  
  366.     /**
  367.      * @deprecated    As of Java Servlet API 2.1, with no replacement.
  368.      *
  369.      * <p>This method was originally defined to return an 
  370.      * <code>Enumeration</code>
  371.      * of all the servlet names known to this context. In this version,
  372.      * this method always returns an empty <code>Enumeration</code> and 
  373.      * remains only to preserve binary compatibility. This method will 
  374.      * be permanently removed in a future version of the Java Servlet API.
  375.      *
  376.      */
  377.  
  378.     public Enumeration getServletNames();
  379.     
  380.   
  381.   
  382.     
  383.     
  384.     /**
  385.      *
  386.      * Writes the specified message to a servlet log file, usually
  387.      * an event log. The name and type of the servlet log file is 
  388.      * specific to the servlet container.
  389.      *
  390.      *
  391.      * @param msg     a <code>String</code> specifying the 
  392.      *            message to be written to the log file
  393.      *
  394.      */
  395.      
  396.     public void log(String msg);
  397.     
  398.     
  399.     
  400.     
  401.  
  402.     /**
  403.      * @deprecated    As of Java Servlet API 2.1, use
  404.      *             {@link #log(String message, Throwable throwable)} 
  405.      *            instead.
  406.      *
  407.      * <p>This method was originally defined to write an 
  408.      * exception's stack trace and an explanatory error message
  409.      * to the servlet log file.
  410.      *
  411.      */
  412.  
  413.     public void log(Exception exception, String msg);
  414.     
  415.     
  416.     
  417.     
  418.  
  419.     /**
  420.      * Writes an explanatory message and a stack trace
  421.      * for a given <code>Throwable</code> exception
  422.      * to the servlet log file. The name and type of the servlet log 
  423.      * file is specific to the servlet container, usually an event log.
  424.      *
  425.      *
  426.      * @param message         a <code>String</code> that 
  427.      *                describes the error or exception
  428.      *
  429.      * @param throwable     the <code>Throwable</code> error 
  430.      *                or exception
  431.      *
  432.      */
  433.     
  434.     public void log(String message, Throwable throwable);
  435.     
  436.     
  437.     
  438.     
  439.     
  440.     /**
  441.      * Returns a <code>String</code> containing the real path 
  442.      * for a given virtual path. For example, the virtual path "/index.html"
  443.      * has a real path of whatever file on the server's filesystem would be
  444.      * served by a request for "/index.html".
  445.      *
  446.      * <p>The real path returned will be in a form
  447.      * appropriate to the computer and operating system on
  448.      * which the servlet container is running, including the
  449.      * proper path separators. This method returns <code>null</code>
  450.      * if the servlet container cannot translate the virtual path
  451.      * to a real path for any reason (such as when the content is
  452.      * being made available from a <code>.war</code> archive).
  453.      *
  454.      *
  455.      * @param path     a <code>String</code> specifying a virtual path
  456.      *
  457.      *
  458.      * @return         a <code>String</code> specifying the real path,
  459.      *                  or null if the translation cannot be performed
  460.      *            
  461.      *
  462.      */
  463.  
  464.     public String getRealPath(String path);
  465.     
  466.     
  467.  
  468.  
  469.     /**
  470.      * Returns the name and version of the servlet container on which
  471.      * the servlet is running. 
  472.      *
  473.      * <p>The form of the returned string is 
  474.      * <i>servername</i>/<i>versionnumber</i>.
  475.      * For example, the JavaServer Web Development Kit may return the string
  476.      * <code>JavaServer Web Dev Kit/1.0</code>.
  477.      *
  478.      * <p>The servlet container may return other optional information 
  479.      * after the primary string in parentheses, for example,
  480.      * <code>JavaServer Web Dev Kit/1.0 (JDK 1.1.6; Windows NT 4.0 x86)</code>.
  481.      *
  482.      *
  483.      * @return         a <code>String</code> containing at least the 
  484.      *            servlet container name and version number
  485.      *
  486.      */
  487.  
  488.     public String getServerInfo();
  489.     
  490.     
  491.  
  492.  
  493.     /**
  494.      * Returns a <code>String</code> containing the value of the named
  495.      * context-wide initialization parameter, or <code>null</code> if the 
  496.      * parameter does not exist.
  497.      *
  498.      * <p>This method can make available configuration information useful
  499.      * to an entire "web application".  For example, it can provide a 
  500.      * webmaster's email address or the name of a system that holds 
  501.      * critical data.
  502.      *
  503.      * @param    name    a <code>String</code> containing the name of the
  504.      *                  parameter whose value is requested
  505.      * 
  506.      * @return         a <code>String</code> containing at least the 
  507.      *            servlet container name and version number
  508.      *
  509.      * @see ServletConfig#getInitParameter
  510.      */
  511.  
  512.     public String getInitParameter(String name);
  513.     
  514.     
  515.  
  516.  
  517.     /**
  518.      * Returns the names of the context's initialization parameters as an
  519.      * <code>Enumeration</code> of <code>String</code> objects, or an
  520.      * empty <code>Enumeration</code> if the context has no initialization
  521.      * parameters.
  522.      *
  523.      * @return         an <code>Enumeration</code> of <code>String</code> 
  524.      *                  objects containing the names of the context's
  525.      *                  initialization parameters
  526.      *
  527.      * @see ServletConfig#getInitParameter
  528.      */
  529.  
  530.     public Enumeration getInitParameterNames();
  531.     
  532.     
  533.  
  534.     /**
  535.      * Returns the servlet container attribute with the given name, 
  536.      * or <code>null</code> if there is no attribute by that name.
  537.      * An attribute allows a servlet container to give the
  538.      * servlet additional information not
  539.      * already provided by this interface. See your
  540.      * server documentation for information about its attributes.
  541.      * A list of supported attributes can be retrieved using
  542.      * <code>getAttributeNames</code>.
  543.      *
  544.      * <p>The attribute is returned as a <code>java.lang.Object</code>
  545.      * or some subclass.
  546.      * Attribute names should follow the same convention as package
  547.      * names. The Java Servlet API specification reserves names
  548.      * matching <code>java.*</code>, <code>javax.*</code>,
  549.      * and <code>sun.*</code>.
  550.      *
  551.      *
  552.      * @param name     a <code>String</code> specifying the name 
  553.      *            of the attribute
  554.      *
  555.      * @return         an <code>Object</code> containing the value 
  556.      *            of the attribute, or <code>null</code>
  557.      *            if no attribute exists matching the given
  558.      *            name
  559.      *
  560.      * @see         ServletContext#getAttributeNames
  561.      *
  562.      */
  563.   
  564.     public Object getAttribute(String name);
  565.     
  566.     
  567.     
  568.  
  569.     /**
  570.      * Returns an <code>Enumeration</code> containing the 
  571.      * attribute names available
  572.      * within this servlet context. Use the
  573.      * {@link #getAttribute} method with an attribute name
  574.      * to get the value of an attribute.
  575.      *
  576.      * @return         an <code>Enumeration</code> of attribute 
  577.      *            names
  578.      *
  579.      * @see        #getAttribute
  580.      *
  581.      */
  582.  
  583.     public Enumeration getAttributeNames();
  584.     
  585.     
  586.     
  587.     
  588.     /**
  589.      *
  590.      * Binds an object to a given attribute name in this servlet context. If
  591.      * the name specified is already used for an attribute, this
  592.      * method will remove the old attribute and bind the name
  593.      * to the new attribute.
  594.      *
  595.      * <p>Attribute names should follow the same convention as package
  596.      * names. The Java Servlet API specification reserves names
  597.      * matching <code>java.*</code>, <code>javax.*</code>, and
  598.      * <code>sun.*</code>.
  599.      *
  600.      *
  601.      * @param name     a <code>String</code> specifying the name 
  602.      *            of the attribute
  603.      *
  604.      * @param object     an <code>Object</code> representing the
  605.      *            attribute to be bound
  606.      *
  607.      *
  608.      *
  609.      */
  610.     
  611.     public void setAttribute(String name, Object object);
  612.     
  613.     
  614.  
  615.  
  616.  
  617.     /**
  618.      * Removes the attribute with the given name from 
  619.      * the servlet context. After removal, subsequent calls to
  620.      * {@link #getAttribute} to retrieve the attribute's value
  621.      * will return <code>null</code>.
  622.      *
  623.      *
  624.      * @param name    a <code>String</code> specifying the name 
  625.      *             of the attribute to be removed
  626.      *
  627.      */
  628.  
  629.     public void removeAttribute(String name);
  630. }
  631.  
  632.  
  633.  
  634.  
  635.  
  636.  
  637.  
  638.