📄 httpservletresponse.java
字号:
/*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowlegement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their names without prior written
* permission of the Apache Group.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*
* This source code implements specifications defined by the Java
* Community Process. In order to remain compliant with the specification
* DO NOT add / change / or delete method signatures!
*/
package javax.servlet.http;
import javax.servlet.ServletResponse;
import javax.servlet.ServletException;
import java.io.IOException;
/**
*
* Extends the {@link ServletResponse} interface to provide HTTP-specific
* functionality in sending a response. For example, it has methods
* to access HTTP headers and cookies.
*
* <p>The servlet container creates an <code>HttpServletRequest</code> object
* and passes it as an argument to the servlet's service methods
* (<code>doGet</code>, <code>doPost</code>, etc).
*
*
* @author Various
* @version $Version$
*
* @see javax.servlet.ServletResponse
*
*/
public interface HttpServletResponse extends ServletResponse {
/**
* Adds the specified cookie to the response. This method can be called
* multiple times to set more than one cookie.
*
* @param cookie the Cookie to return to the client
*
*/
public void addCookie(Cookie cookie);
/**
* Returns a boolean indicating whether the named response header
* has already been set.
*
* @param name the header name
* @return <code>true</code> if the named response header
* has already been set;
* <code>false</code> otherwise
*/
public boolean containsHeader(String name);
/**
* Encodes the specified URL by including the session ID in it,
* or, if encoding is not needed, returns the URL unchanged.
* The implementation of this method includes the logic to
* determine whether the session ID needs to be encoded in the URL.
* For example, if the browser supports cookies, or session
* tracking is turned off, URL encoding is unnecessary.
*
* <p>For robust session tracking, all URLs emitted by a servlet
* should be run through this
* method. Otherwise, URL rewriting cannot be used with browsers
* which do not support cookies.
*
* @param url the url to be encoded.
* @return the encoded URL if encoding is needed;
* the unchanged URL otherwise.
*/
public String encodeURL(String url);
/**
* Encodes the specified URL for use in the
* <code>sendRedirect</code> method or, if encoding is not needed,
* returns the URL unchanged. The implementation of this method
* includes the logic to determine whether the session ID
* needs to be encoded in the URL. Because the rules for making
* this determination can differ from those used to decide whether to
* encode a normal link, this method is seperate from the
* <code>encodeURL</code> method.
*
* <p>All URLs sent to the <code>HttpServletResponse.sendRedirect</code>
* method should be run through this method. Otherwise, URL
* rewriting cannot be used with browsers which do not support
* cookies.
*
* @param url the url to be encoded.
* @return the encoded URL if encoding is needed;
* the unchanged URL otherwise.
*
* @see #sendRedirect
* @see #encodeUrl
*/
public String encodeRedirectURL(String url);
/**
* @deprecated As of version 2.1, use encodeURL(String url) instead
*
* @param url the url to be encoded.
* @return the encoded URL if encoding is needed;
* the unchanged URL otherwise.
*/
public String encodeUrl(String url);
/**
* @deprecated As of version 2.1, use
* encodeRedirectURL(String url) instead
*
* @param url the url to be encoded.
* @return the encoded URL if encoding is needed;
* the unchanged URL otherwise.
*/
public String encodeRedirectUrl(String url);
/**
* Sends an error response to the client using the specified status
* code and descriptive message. The server generally creates the
* response to look like a normal server error page.
*
* <p>If the response has already been committed, this method throws
* an IllegalStateException.
* After using this method, the response should be considered
* to be committed and should not be written to.
*
* @param sc the error status code
* @param msg the descriptive message
* @exception IOException If an input or output exception occurs
* @exception IllegalStateException If the response was committed
* before this method call
*/
public void sendError(int sc, String msg) throws IOException;
/**
* Sends an error response to the client using the specified
* status. The server generally creates the
* response to look like a normal server error page.
*
* <p>If the response has already been committed, this method throws
* an IllegalStateException.
* After using this method, the response should be considered
* to be committed and should not be written to.
*
* @param sc the error status code
* @exception IOException If an input or output exception occurs
* @exception IllegalStateException If the response was committed
*/
public void sendError(int sc) throws IOException;
/**
* Sends a temporary redirect response to the client using the
* specified redirect location URL. This method can accept relative URLs;
* the servlet container will convert the relative URL to an absolute URL
* before sending the response to the client.
*
* <p>If the response has already been committed, this method throws
* an IllegalStateException.
* After using this method, the response should be considered
* to be committed and should not be written to.
*
* @param location the redirect location URL
* @exception IOException If an input or output exception occurs
* @exception IllegalStateException If the response was committed
*/
public void sendRedirect(String location) throws IOException;
/**
*
* Sets a response header with the given name and
* date-value. The date is specified in terms of
* milliseconds since the epoch. If the header had already
* been set, the new value overwrites the previous one. The
* <code>containsHeader</code> method can be used to test for the
* presence of a header before setting its value.
*
* @param name the name of the header to set
* @param value the assigned date value
*
* @see #containsHeader
* @see #addDateHeader
*/
public void setDateHeader(String name, long date);
/**
*
* Adds a response header with the given name and
* date-value. The date is specified in terms of
* milliseconds since the epoch. This method allows response headers
* to have multiple values.
*
* @param name the name of the header to set
* @param value the additional date value
*
* @see #setDateHeader
*/
public void addDateHeader(String name, long date);
/**
*
* Sets a response header with the given name and value.
* If the header had already been set, the new value overwrites the
* previous one. The <code>containsHeader</code> method can be
* used to test for the presence of a header before setting its
* value.
*
* @param name the name of the header
* @param value the header value
*
* @see #containsHeader
* @see #addHeader
*/
public void setHeader(String name, String value);
/**
* Adds a response header with the given name and value.
* This method allows response headers to have multiple values.
*
* @param name the name of the header
* @param value the additional header value
*
* @see #setHeader
*/
public void addHeader(String name, String value);
/**
* Sets a response header with the given name and
* integer value. If the header had already been set, the new value
* overwrites the previous one. The <code>containsHeader</code>
* method can be used to test for the presence of a header before
* setting its value.
*
* @param name the name of the header
* @param value the assigned integer value
*
* @see #containsHeader
* @see #addIntHeader
*/
public void setIntHeader(String name, int value);
/**
* Adds a response header with the given name and
* integer value. This method allows response headers to have multiple
* values.
*
* @param name the name of the header
* @param value the assigned integer value
*
* @see #setIntHeader
*/
public void addIntHeader(String name, int value);
/**
* Sets the status code for this response. This method is used to
* set the return status code when there is no error (for example,
* for the status codes SC_OK or SC_MOVED_TEMPORARILY). If there
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -