001: /*
002: * Copyright (c) 1998-2001 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package javax.servlet.http;
030:
031: import javax.servlet.ServletResponse;
032: import java.io.IOException;
033:
034: /**
035: * HttpServletResponse extends ServletResponse allowing servlets to
036: * set the status and headers.
037: *
038: * <h4>Useful Headers</h4>
039: *
040: * <table>
041: * <tr><td>Expires
042: * <td>Lets clients cache the page. Resin can use Expires to
043: * internally cache the page.
044: * </table>
045: */
046: public interface HttpServletResponse extends ServletResponse {
047: public final static int SC_ACCEPTED = 202;
048: public final static int SC_BAD_GATEWAY = 502;
049: public final static int SC_BAD_REQUEST = 400;
050: public final static int SC_CONFLICT = 409;
051: public final static int SC_CONTINUE = 100;
052: public final static int SC_CREATED = 201;
053: public final static int SC_EXPECTATION_FAILED = 417;
054: public final static int SC_FORBIDDEN = 403;
055: public final static int SC_GATEWAY_TIMEOUT = 504;
056: public final static int SC_GONE = 410;
057: public final static int SC_HTTP_VERSION_NOT_SUPPORTED = 505;
058: public final static int SC_INTERNAL_SERVER_ERROR = 500;
059: public final static int SC_LENGTH_REQUIRED = 411;
060: public final static int SC_METHOD_NOT_ALLOWED = 405;
061: public final static int SC_MOVED_PERMANENTLY = 301;
062: public final static int SC_MOVED_TEMPORARILY = 302;
063: public final static int SC_FOUND = 302;
064: public final static int SC_MULTIPLE_CHOICES = 300;
065: public final static int SC_NO_CONTENT = 204;
066: public final static int SC_NON_AUTHORITATIVE_INFORMATION = 203;
067: public final static int SC_NOT_ACCEPTABLE = 406;
068: public final static int SC_NOT_FOUND = 404;
069: public final static int SC_NOT_IMPLEMENTED = 501;
070: public final static int SC_NOT_MODIFIED = 304;
071: public final static int SC_OK = 200;
072: public final static int SC_PARTIAL_CONTENT = 206;
073: public final static int SC_PAYMENT_REQUIRED = 402;
074: public final static int SC_PRECONDITION_FAILED = 412;
075: public final static int SC_PROXY_AUTHENTICATION_REQUIRED = 407;
076: public final static int SC_REQUEST_ENTITY_TOO_LARGE = 413;
077: public final static int SC_REQUEST_TIMEOUT = 408;
078: public final static int SC_REQUEST_URI_TOO_LONG = 414;
079: public final static int SC_REQUESTED_RANGE_NOT_SATISFIABLE = 416;
080: public final static int SC_RESET_CONTENT = 205;
081: public final static int SC_SEE_OTHER = 303;
082: public final static int SC_SERVICE_UNAVAILABLE = 503;
083: public final static int SC_SWITCHING_PROTOCOLS = 101;
084: public final static int SC_UNAUTHORIZED = 401;
085: public final static int SC_UNSUPPORTED_MEDIA_TYPE = 415;
086: public final static int SC_USE_PROXY_TYPE = 305;
087:
088: /**
089: * Sets the HTTP status
090: *
091: * @param sc the HTTP status code
092: */
093: public void setStatus(int sc);
094:
095: /**
096: * Sends an HTTP error page based on the status code
097: *
098: * @param sc the HTTP status code
099: */
100: public void sendError(int sc, String msg) throws IOException;
101:
102: /**
103: * Sends an HTTP error page based on the status code
104: *
105: * @param sc the HTTP status code
106: */
107: public void sendError(int sc) throws IOException;
108:
109: /**
110: * Redirects the client to another page.
111: *
112: * @param location the location to redirect to.
113: */
114: public void sendRedirect(String location) throws IOException;
115:
116: /**
117: * Sets a header. This will override a previous header
118: * with the same name.
119: *
120: * @param name the header name
121: * @param value the header value
122: */
123: public void setHeader(String name, String value);
124:
125: /**
126: * Adds a header. If another header with the same name exists, both
127: * will be sent to the client.
128: *
129: * @param name the header name
130: * @param value the header value
131: */
132: public void addHeader(String name, String value);
133:
134: /**
135: * Returns true if the output headers include <code>name</code>
136: *
137: * @param name the header name to test
138: */
139: public boolean containsHeader(String name);
140:
141: /**
142: * Sets a header by converting a date to a string.
143: *
144: * <p>To set the page to expire in 15 seconds use the following:
145: * <pre><code>
146: * long now = System.currentTime();
147: * response.setDateHeader("Expires", now + 15000);
148: * </code></pre>
149: *
150: * @param name name of the header
151: * @param date the date in milliseconds since the epoch.
152: */
153: public void setDateHeader(String name, long date);
154:
155: /**
156: * Adds a header by converting a date to a string.
157: *
158: * @param name name of the header
159: * @param date the date in milliseconds since the epoch.
160: */
161: public void addDateHeader(String name, long date);
162:
163: /**
164: * Sets a header by converting an integer value to a string.
165: *
166: * @param name name of the header
167: * @param value the value as an integer
168: */
169: public void setIntHeader(String name, int value);
170:
171: /**
172: * Adds a header by converting an integer value to a string.
173: *
174: * @param name name of the header
175: * @param value the value as an integer
176: */
177: public void addIntHeader(String name, int value);
178:
179: /**
180: * Sends a new cookie to the client.
181: */
182: public void addCookie(Cookie cookie);
183:
184: /**
185: * Encodes session information in a URL. Calling this will enable
186: * sessions for users who have disabled cookies.
187: *
188: * @param url the url to encode
189: * @return a url with session information encoded
190: */
191: public String encodeURL(String url);
192:
193: /**
194: * Encodes session information in a URL suitable for
195: * <code>sendRedirect()</code>
196: *
197: * @param url the url to encode
198: * @return a url with session information encoded
199: */
200: public String encodeRedirectURL(String name);
201:
202: /**
203: * @deprecated
204: */
205: public void setStatus(int sc, String msg);
206:
207: /**
208: * @deprecated
209: */
210: public String encodeUrl(String url);
211:
212: /**
213: * @deprecated
214: */
215: public String encodeRedirectUrl(String url);
216: }
|