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 / ServletRequest.java < prev    next >
Encoding:
Java Source  |  2001-10-22  |  17.6 KB  |  558 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.BufferedReader;
  64. import java.io.IOException;
  65. import java.io.UnsupportedEncodingException;
  66. import java.util.Enumeration;
  67. import java.util.Locale;
  68.  
  69.  
  70.  
  71. /**
  72.  * Defines an object to provide client request information to a servlet.  The
  73.  * servlet container creates a <code>ServletRequest</code> object and passes
  74.  * it as an argument to the servlet's <code>service</code> method.
  75.  *
  76.  * <p>A <code>ServletRequest</code> object provides data including
  77.  * parameter name and values, attributes, and an input stream.
  78.  * Interfaces that extend <code>ServletRequest</code> can provide
  79.  * additional protocol-specific data (for example, HTTP data is
  80.  * provided by {@link javax.servlet.http.HttpServletRequest}.
  81.  * 
  82.  * @author     Various
  83.  * @version     $Version$
  84.  *
  85.  * @see     javax.servlet.http.HttpServletRequest
  86.  *
  87.  */
  88.  
  89. public interface ServletRequest {
  90.  
  91.  
  92.  
  93.  
  94.     /**
  95.      *
  96.      * Returns the value of the named attribute as an <code>Object</code>,
  97.      * or <code>null</code> if no attribute of the given name exists. 
  98.      *
  99.      * <p> Attributes can be set two ways.  The servlet container may set
  100.      * attributes to make available custom information about a request.
  101.      * For example, for requests made using HTTPS, the attribute
  102.      * <code>javax.servlet.request.X509Certificate</code> can be used to
  103.      * retrieve information on the certificate of the client.  Attributes
  104.      * can also be set programatically using 
  105.      * {@link ServletRequest#setAttribute}.  This allows information to be
  106.      * embedded into a request before a {@link RequestDispatcher} call.
  107.      *
  108.      * <p>Attribute names should follow the same conventions as package
  109.      * names. This specification reserves names matching <code>java.*</code>,
  110.      * <code>javax.*</code>, and <code>sun.*</code>. 
  111.      *
  112.      * @param name    a <code>String</code> specifying the name of 
  113.      *            the attribute
  114.      *
  115.      * @return        an <code>Object</code> containing the value 
  116.      *            of the attribute, or <code>null</code> if
  117.      *            the attribute does not exist
  118.      *
  119.      */
  120.  
  121.     public Object getAttribute(String name);
  122.     
  123.     
  124.  
  125.     /**
  126.      * Returns an <code>Enumeration</code> containing the
  127.      * names of the attributes available to this request. 
  128.      * This method returns an empty <code>Enumeration</code>
  129.      * if the request has no attributes available to it.
  130.      * 
  131.      *
  132.      * @return        an <code>Enumeration</code> of strings 
  133.      *            containing the names 
  134.      *             of the request's attributes
  135.      *
  136.      */
  137.  
  138.     public Enumeration getAttributeNames();
  139.     
  140.     
  141.     
  142.     
  143.     /**
  144.      * Returns the name of the character encoding used in the body of this
  145.      * request. This method returns <code>null</code> if the request
  146.      * does not specify a character encoding
  147.      * 
  148.      *
  149.      * @return        a <code>String</code> containing the name of 
  150.      *            the chararacter encoding, or <code>null</code>
  151.      *            if the request does not specify a character encoding
  152.      *
  153.      */
  154.  
  155.     public String getCharacterEncoding();
  156.     
  157.     
  158.     
  159.     
  160.     /**
  161.      * Returns the length, in bytes, of the request body 
  162.      * and made available by the input stream, or -1 if the
  163.      * length is not known. For HTTP servlets, same as the value
  164.      * of the CGI variable CONTENT_LENGTH.
  165.      *
  166.      * @return        an integer containing the length of the 
  167.      *             request body or -1 if the length is not known
  168.      *
  169.      */
  170.  
  171.     public int getContentLength();
  172.     
  173.     
  174.     
  175.  
  176.     /**
  177.      * Returns the MIME type of the body of the request, or 
  178.      * <code>null</code> if the type is not known. For HTTP servlets, 
  179.      * same as the value of the CGI variable CONTENT_TYPE.
  180.      *
  181.      * @return        a <code>String</code> containing the name 
  182.      *            of the MIME type of 
  183.      *             the request, or -1 if the type is not known
  184.      *
  185.      */
  186.  
  187.     public String getContentType();
  188.     
  189.     
  190.     
  191.  
  192.     /**
  193.      * Retrieves the body of the request as binary data using
  194.      * a {@link ServletInputStream}.  Either this method or 
  195.      * {@link #getReader} may be called to read the body, not both.
  196.      *
  197.      * @return            a {@link ServletInputStream} object containing
  198.      *                 the body of the request
  199.      *
  200.      * @exception IllegalStateException  if the {@link #getReader} method
  201.      *                      has already been called for this request
  202.      *
  203.      * @exception IOException        if an input or output exception occurred
  204.      *
  205.      */
  206.  
  207.     public ServletInputStream getInputStream() throws IOException; 
  208.      
  209.     
  210.     
  211.  
  212.     /**
  213.      * Returns the value of a request parameter as a <code>String</code>,
  214.      * or <code>null</code> if the parameter does not exist. Request parameters
  215.      * are extra information sent with the request.  For HTTP servlets,
  216.      * parameters are contained in the query string or posted form data.
  217.      *
  218.      * <p>You should only use this method when you are sure the
  219.      * parameter has only one value. If the parameter might have
  220.      * more than one value, use {@link #getParameterValues}.
  221.      *
  222.      * <p>If you use this method with a multivalued
  223.      * parameter, the value returned is equal to the first value
  224.      * in the array returned by <code>getParameterValues</code>.
  225.      *
  226.      * <p>If the parameter data was sent in the request body, such as occurs
  227.      * with an HTTP POST request, then reading the body directly via {@link
  228.      * #getInputStream} or {@link #getReader} can interfere
  229.      * with the execution of this method.
  230.      *
  231.      * @param name     a <code>String</code> specifying the 
  232.      *            name of the parameter
  233.      *
  234.      * @return        a <code>String</code> representing the 
  235.      *            single value of the parameter
  236.      *
  237.      * @see         #getParameterValues
  238.      *
  239.      */
  240.  
  241.     public String getParameter(String name);
  242.     
  243.     
  244.     
  245.  
  246.     /**
  247.      *
  248.      * Returns an <code>Enumeration</code> of <code>String</code>
  249.      * objects containing the names of the parameters contained
  250.      * in this request. If the request has 
  251.      * no parameters, the method returns an 
  252.      * empty <code>Enumeration</code>. 
  253.      *
  254.      * @return        an <code>Enumeration</code> of <code>String</code>
  255.      *            objects, each <code>String</code> containing
  256.      *             the name of a request parameter; or an 
  257.      *            empty <code>Enumeration</code> if the
  258.      *            request has no parameters
  259.      *
  260.      */
  261.      
  262.     public Enumeration getParameterNames();
  263.     
  264.     
  265.     
  266.  
  267.     /**
  268.      * Returns an array of <code>String</code> objects containing 
  269.      * all of the values the given request parameter has, or 
  270.      * <code>null</code> if the parameter does not exist.
  271.      *
  272.      * <p>If the parameter has a single value, the array has a length
  273.      * of 1.
  274.      *
  275.      * @param name    a <code>String</code> containing the name of 
  276.      *            the parameter whose value is requested
  277.      *
  278.      * @return        an array of <code>String</code> objects 
  279.      *            containing the parameter's values
  280.      *
  281.      * @see        #getParameter
  282.      *
  283.      */
  284.  
  285.     public String[] getParameterValues(String name);
  286.     
  287.     
  288.     
  289.  
  290.     /**
  291.      * Returns the name and version of the protocol the request uses
  292.      * in the form <i>protocol/majorVersion.minorVersion</i>, for 
  293.      * example, HTTP/1.1. For HTTP servlets, the value
  294.      * returned is the same as the value of the CGI variable 
  295.      * <code>SERVER_PROTOCOL</code>.
  296.      *
  297.      * @return        a <code>String</code> containing the protocol 
  298.      *            name and version number
  299.      *
  300.      */
  301.     
  302.     public String getProtocol();
  303.     
  304.     
  305.     
  306.  
  307.     /**
  308.      * Returns the name of the scheme used to make this request, 
  309.      * for example,
  310.      * <code>http</code>, <code>https</code>, or <code>ftp</code>.
  311.      * Different schemes have different rules for constructing URLs,
  312.      * as noted in RFC 1738.
  313.      *
  314.      * @return        a <code>String</code> containing the name 
  315.      *            of the scheme used to make this request
  316.      *
  317.      */
  318.  
  319.     public String getScheme();
  320.     
  321.     
  322.     
  323.  
  324.     /**
  325.      * Returns the host name of the server that received the request.
  326.      * For HTTP servlets, same as the value of the CGI variable 
  327.      * <code>SERVER_NAME</code>.
  328.      *
  329.      * @return        a <code>String</code> containing the name 
  330.      *            of the server to which the request was sent
  331.      */
  332.  
  333.     public String getServerName();
  334.     
  335.     
  336.     
  337.  
  338.     /**
  339.      * Returns the port number on which this request was received.
  340.      * For HTTP servlets, same as the value of the CGI variable 
  341.      * <code>SERVER_PORT</code>.
  342.      *
  343.      * @return        an integer specifying the port number
  344.      *
  345.      */
  346.  
  347.     public int getServerPort();
  348.     
  349.     
  350.     
  351.     /**
  352.      * Retrieves the body of the request as character data using
  353.      * a <code>BufferedReader</code>.  The reader translates the character
  354.      * data according to the character encoding used on the body.
  355.      * Either this method or {@link #getReader} may be called to read the
  356.      * body, not both.
  357.      * 
  358.      *
  359.      * @return                    a <code>BufferedReader</code>
  360.      *                        containing the body of the request    
  361.      *
  362.      * @exception UnsupportedEncodingException     if the character set encoding
  363.      *                         used is not supported and the 
  364.      *                        text cannot be decoded
  365.      *
  366.      * @exception IllegalStateException       if {@link #getInputStream} method
  367.      *                         has been called on this request
  368.      *
  369.      * @exception IOException              if an input or output exception occurred
  370.      *
  371.      * @see                     #getInputStream
  372.      *
  373.      */
  374.  
  375.     public BufferedReader getReader() throws IOException;
  376.     
  377.     
  378.     
  379.  
  380.     /**
  381.      * Returns the Internet Protocol (IP) address of the client 
  382.      * that sent the request.  For HTTP servlets, same as the value of the 
  383.      * CGI variable <code>REMOTE_ADDR</code>.
  384.      *
  385.      * @return        a <code>String</code> containing the 
  386.      *            IP address of the client that sent the request
  387.      *
  388.      */
  389.     
  390.     public String getRemoteAddr();
  391.     
  392.     
  393.     
  394.  
  395.     /**
  396.      * Returns the fully qualified name of the client that sent the
  397.      * request, or the IP address of the client if the name cannot be
  398.      * determined. For HTTP servlets, same as the value of the CGI variable 
  399.      * <code>REMOTE_HOST</code>.
  400.      *
  401.      * @return        a <code>String</code> containing the fully qualified name 
  402.      *            of the client
  403.      *
  404.      */
  405.  
  406.     public String getRemoteHost();
  407.     
  408.     
  409.     
  410.  
  411.     /**
  412.      *
  413.      * Stores an attribute in this request.
  414.      * Attributes are reset between requests.  This method is most
  415.      * often used in conjunction with {@link RequestDispatcher}.
  416.      *
  417.      * <p>Attribute names should follow the same conventions as
  418.      * package names. Names beginning with <code>java.*</code>,
  419.      * <code>javax.*</code>, and <code>com.sun.*</code>, are
  420.      * reserved for use by Sun Microsystems.
  421.      *
  422.      *
  423.      * @param name            a <code>String</code> specifying 
  424.      *                    the name of the attribute
  425.      *
  426.      * @param o                the <code>Object</code> to be stored
  427.      *
  428.      */
  429.  
  430.     public void setAttribute(String name, Object o);
  431.     
  432.     
  433.     
  434.  
  435.     /**
  436.      *
  437.      * Removes an attribute from this request.  This method is not
  438.      * generally needed as attributes only persist as long as the request
  439.      * is being handled.
  440.      *
  441.      * <p>Attribute names should follow the same conventions as
  442.      * package names. Names beginning with <code>java.*</code>,
  443.      * <code>javax.*</code>, and <code>com.sun.*</code>, are
  444.      * reserved for use by Sun Microsystems.
  445.      *
  446.      *
  447.      * @param name            a <code>String</code> specifying 
  448.      *                    the name of the attribute to remove
  449.      *
  450.      */
  451.  
  452.     public void removeAttribute(String name);
  453.     
  454.     
  455.     
  456.  
  457.     /**
  458.      *
  459.      * Returns the preferred <code>Locale</code> that the client will 
  460.      * accept content in, based on the Accept-Language header.
  461.      * If the client request doesn't provide an Accept-Language header,
  462.      * this method returns the default locale for the server.
  463.      *
  464.      *
  465.      * @return        the preferred <code>Locale</code> for the client
  466.      *
  467.      */
  468.  
  469.     public Locale getLocale();
  470.     
  471.     
  472.     
  473.  
  474.     /**
  475.      *
  476.      * Returns an <code>Enumeration</code> of <code>Locale</code> objects
  477.      * indicating, in decreasing order starting with the preferred locale, the
  478.      * locales that are acceptable to the client based on the Accept-Language
  479.      * header.
  480.      * If the client request doesn't provide an Accept-Language header,
  481.      * this method returns an <code>Enumeration</code> containing one 
  482.      * <code>Locale</code>, the default locale for the server.
  483.      *
  484.      *
  485.      * @return        an <code>Enumeration</code> of preferred 
  486.      *                  <code>Locale</code> objects for the client
  487.      *
  488.      */
  489.  
  490.     public Enumeration getLocales();
  491.     
  492.     
  493.     
  494.  
  495.     /**
  496.      *
  497.      * Returns a boolean indicating whether this request was made using a
  498.      * secure channel, such as HTTPS.
  499.      *
  500.      *
  501.      * @return        a boolean indicating if the request was made using a
  502.      *                  secure channel
  503.      *
  504.      */
  505.  
  506.     public boolean isSecure();
  507.     
  508.     
  509.     
  510.  
  511.     /**
  512.      *
  513.      * Returns a {@link RequestDispatcher} object that acts as a wrapper for
  514.      * the resource located at the given path.  
  515.      * A <code>RequestDispatcher</code> object can be used to forward
  516.      * a request to the resource or to include the resource in a response.
  517.      * The resource can be dynamic or static.
  518.      *
  519.      * <p>The pathname specified may be relative, although it cannot extend
  520.      * outside the current servlet context.  If the path begins with 
  521.      * a "/" it is interpreted as relative to the current context root.  
  522.      * This method returns <code>null</code> if the servlet container
  523.      * cannot return a <code>RequestDispatcher</code>.
  524.      *
  525.      * <p>The difference between this method and {@link
  526.      * ServletContext#getRequestDispatcher} is that this method can take a
  527.      * relative path.
  528.      *
  529.      * @param path      a <code>String</code> specifying the pathname
  530.      *                  to the resource
  531.      *
  532.      * @return          a <code>RequestDispatcher</code> object
  533.      *                  that acts as a wrapper for the resource
  534.      *                  at the specified path
  535.      *
  536.      * @see             RequestDispatcher
  537.      * @see             ServletContext#getRequestDispatcher
  538.      *
  539.      */
  540.  
  541.     public RequestDispatcher getRequestDispatcher(String path);
  542.     
  543.     
  544.     
  545.  
  546.     /**
  547.      * 
  548.      * @deprecated     As of Version 2.1 of the Java Servlet API,
  549.      *             use {@link ServletContext#getRealPath} instead.
  550.      *
  551.      */
  552.  
  553.     public String getRealPath(String path);
  554.     
  555.     
  556. }
  557.  
  558.