blob: 0335f6b833a1d7099b8bc2a5286c764f6f56df7d [file] [log] [blame]
Michael E. Rodriguezd8af66f2005-12-08 20:55:55 +00001/*
2 * Copyright 1999,2005 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package javax.servlet.http;
18
19import javax.servlet.ServletResponse;
20import java.io.IOException;
21
22/**
23 *
24 * Extends the {@link ServletResponse} interface to provide HTTP-specific
25 * functionality in sending a response. For example, it has methods
26 * to access HTTP headers and cookies.
27 *
28 * <p>The servlet container creates an <code>HttpServletRequest</code> object
29 * and passes it as an argument to the servlet's service methods
30 * (<code>doGet</code>, <code>doPost</code>, etc).
31 *
32 *
33 * @author Various
34 * @version $Version$
35 *
36 * @see javax.servlet.ServletResponse
37 *
38 */
39
40
41
42public interface HttpServletResponse extends ServletResponse {
43
44 /**
45 * Adds the specified cookie to the response. This method can be called
46 * multiple times to set more than one cookie.
47 *
48 * @param cookie the Cookie to return to the client
49 *
50 */
51
52 public void addCookie(Cookie cookie);
53
54 /**
55 * Returns a boolean indicating whether the named response header
56 * has already been set.
57 *
58 * @param name the header name
59 * @return <code>true</code> if the named response header
60 * has already been set;
61 * <code>false</code> otherwise
62 */
63
64 public boolean containsHeader(String name);
65
66 /**
67 * Encodes the specified URL by including the session ID in it,
68 * or, if encoding is not needed, returns the URL unchanged.
69 * The implementation of this method includes the logic to
70 * determine whether the session ID needs to be encoded in the URL.
71 * For example, if the browser supports cookies, or session
72 * tracking is turned off, URL encoding is unnecessary.
73 *
74 * <p>For robust session tracking, all URLs emitted by a servlet
75 * should be run through this
76 * method. Otherwise, URL rewriting cannot be used with browsers
77 * which do not support cookies.
78 *
79 * @param url the url to be encoded.
80 * @return the encoded URL if encoding is needed;
81 * the unchanged URL otherwise.
82 */
83
84 public String encodeURL(String url);
85
86 /**
87 * Encodes the specified URL for use in the
88 * <code>sendRedirect</code> method or, if encoding is not needed,
89 * returns the URL unchanged. The implementation of this method
90 * includes the logic to determine whether the session ID
91 * needs to be encoded in the URL. Because the rules for making
92 * this determination can differ from those used to decide whether to
93 * encode a normal link, this method is seperate from the
94 * <code>encodeURL</code> method.
95 *
96 * <p>All URLs sent to the <code>HttpServletResponse.sendRedirect</code>
97 * method should be run through this method. Otherwise, URL
98 * rewriting cannot be used with browsers which do not support
99 * cookies.
100 *
101 * @param url the url to be encoded.
102 * @return the encoded URL if encoding is needed;
103 * the unchanged URL otherwise.
104 *
105 * @see #sendRedirect
106 * @see #encodeUrl
107 */
108
109 public String encodeRedirectURL(String url);
110
111 /**
112 * @deprecated As of version 2.1, use encodeURL(String url) instead
113 *
114 * @param url the url to be encoded.
115 * @return the encoded URL if encoding is needed;
116 * the unchanged URL otherwise.
117 */
118
119 public String encodeUrl(String url);
120
121 /**
122 * @deprecated As of version 2.1, use
123 * encodeRedirectURL(String url) instead
124 *
125 * @param url the url to be encoded.
126 * @return the encoded URL if encoding is needed;
127 * the unchanged URL otherwise.
128 */
129
130 public String encodeRedirectUrl(String url);
131
132 /**
133 * Sends an error response to the client using the specified
134 * status clearing the buffer. The server defaults to creating the
135 * response to look like an HTML-formatted server error page containing the specified message, setting the content type
136 * to "text/html", leaving cookies and other headers unmodified.
137 *
138 * If an error-page declaration has been made for the web application
139 * corresponding to the status code passed in, it will be served back in
140 * preference to the suggested msg parameter.
141 *
142 * <p>If the response has already been committed, this method throws
143 * an IllegalStateException.
144 * After using this method, the response should be considered
145 * to be committed and should not be written to.
146 *
147 * @param sc the error status code
148 * @param msg the descriptive message
149 * @exception IOException If an input or output exception occurs
150 * @exception IllegalStateException If the response was committed
151 */
152
153 public void sendError(int sc, String msg) throws IOException;
154
155 /**
156 * Sends an error response to the client using the specified status
157 * code and clearing the buffer.
158 * <p>If the response has already been committed, this method throws
159 * an IllegalStateException.
160 * After using this method, the response should be considered
161 * to be committed and should not be written to.
162 *
163 * @param sc the error status code
164 * @exception IOException If an input or output exception occurs
165 * @exception IllegalStateException If the response was committed
166 * before this method call
167 */
168
169 public void sendError(int sc) throws IOException;
170
171 /**
172 * Sends a temporary redirect response to the client using the
173 * specified redirect location URL. This method can accept relative URLs;
174 * the servlet container must convert the relative URL to an absolute URL
175 * before sending the response to the client. If the location is relative
176 * without a leading '/' the container interprets it as relative to
177 * the current request URI. If the location is relative with a leading
178 * '/' the container interprets it as relative to the servlet container root.
179 *
180 * <p>If the response has already been committed, this method throws
181 * an IllegalStateException.
182 * After using this method, the response should be considered
183 * to be committed and should not be written to.
184 *
185 * @param location the redirect location URL
186 * @exception IOException If an input or output exception occurs
187 * @exception IllegalStateException If the response was committed
188 */
189
190 public void sendRedirect(String location) throws IOException;
191
192 /**
193 *
194 * Sets a response header with the given name and
195 * date-value. The date is specified in terms of
196 * milliseconds since the epoch. If the header had already
197 * been set, the new value overwrites the previous one. The
198 * <code>containsHeader</code> method can be used to test for the
199 * presence of a header before setting its value.
200 *
201 * @param name the name of the header to set
202 * @param date the assigned date value
203 *
204 * @see #containsHeader
205 */
206
207 public void setDateHeader(String name, long date);
208
209 /**
210 *
211 * Sets a response header with the given name and value.
212 * If the header had already been set, the new value overwrites the
213 * previous one. The <code>containsHeader</code> method can be
214 * used to test for the presence of a header before setting its
215 * value.
216 *
217 * @param name the name of the header
218 * @param value the header value
219 *
220 * @see #containsHeader
221 */
222
223 public void setHeader(String name, String value);
224
225 /**
226 * Sets a response header with the given name and
227 * integer value. If the header had already been set, the new value
228 * overwrites the previous one. The <code>containsHeader</code>
229 * method can be used to test for the presence of a header before
230 * setting its value.
231 *
232 * @param name the name of the header
233 * @param value the assigned integer value
234 *
235 * @see #containsHeader
236 */
237
238 public void setIntHeader(String name, int value);
239
240 /**
241 * Sets the status code for this response. This method is used to
242 * set the return status code when there is no error (for example,
243 * for the status codes SC_OK or SC_MOVED_TEMPORARILY). If there
244 * is an error, the <code>sendError</code> method should be used
245 * instead.
246 * <p> The container clears the buffer and sets the Location header, preserving
247 * cookies and other headers.
248 *
249 * @param sc the status code
250 *
251 * @see #sendError(int, String)
252 */
253
254 public void setStatus(int sc);
255
256 /**
257 * @deprecated As of version 2.1, due to ambiguous meaning of the
258 * message parameter. To set a status code
259 * use <code>setStatus(int)</code>, to send an error with a description
260 * use <code>sendError(int, String)</code>.
261 *
262 * Sets the status code and message for this response.
263 *
264 * @param sc the status code
265 * @param sm the status message
266 */
267
268 public void setStatus(int sc, String sm);
269
270
271 /*
272 * Server status codes; see RFC 2068.
273 */
274
275 /**
276 * Status code (100) indicating the client can continue.
277 */
278
279 public static final int SC_CONTINUE = 100;
280
281
282 /**
283 * Status code (101) indicating the server is switching protocols
284 * according to Upgrade header.
285 */
286
287 public static final int SC_SWITCHING_PROTOCOLS = 101;
288
289 /**
290 * Status code (200) indicating the request succeeded normally.
291 */
292
293 public static final int SC_OK = 200;
294
295 /**
296 * Status code (201) indicating the request succeeded and created
297 * a new resource on the server.
298 */
299
300 public static final int SC_CREATED = 201;
301
302 /**
303 * Status code (202) indicating that a request was accepted for
304 * processing, but was not completed.
305 */
306
307 public static final int SC_ACCEPTED = 202;
308
309 /**
310 * Status code (203) indicating that the meta information presented
311 * by the client did not originate from the server.
312 */
313
314 public static final int SC_NON_AUTHORITATIVE_INFORMATION = 203;
315
316 /**
317 * Status code (204) indicating that the request succeeded but that
318 * there was no new information to return.
319 */
320
321 public static final int SC_NO_CONTENT = 204;
322
323 /**
324 * Status code (205) indicating that the agent <em>SHOULD</em> reset
325 * the document view which caused the request to be sent.
326 */
327
328 public static final int SC_RESET_CONTENT = 205;
329
330 /**
331 * Status code (206) indicating that the server has fulfilled
332 * the partial GET request for the resource.
333 */
334
335 public static final int SC_PARTIAL_CONTENT = 206;
336
337 /**
338 * Status code (300) indicating that the requested resource
339 * corresponds to any one of a set of representations, each with
340 * its own specific location.
341 */
342
343 public static final int SC_MULTIPLE_CHOICES = 300;
344
345 /**
346 * Status code (301) indicating that the resource has permanently
347 * moved to a new location, and that future references should use a
348 * new URI with their requests.
349 */
350
351 public static final int SC_MOVED_PERMANENTLY = 301;
352
353 /**
354 * Status code (302) indicating that the resource has temporarily
355 * moved to another location, but that future references should
356 * still use the original URI to access the resource.
357 */
358
359 public static final int SC_MOVED_TEMPORARILY = 302;
360
361 /**
362 * Status code (303) indicating that the response to the request
363 * can be found under a different URI.
364 */
365
366 public static final int SC_SEE_OTHER = 303;
367
368 /**
369 * Status code (304) indicating that a conditional GET operation
370 * found that the resource was available and not modified.
371 */
372
373 public static final int SC_NOT_MODIFIED = 304;
374
375 /**
376 * Status code (305) indicating that the requested resource
377 * <em>MUST</em> be accessed through the proxy given by the
378 * <code><em>Location</em></code> field.
379 */
380
381 public static final int SC_USE_PROXY = 305;
382
383 /**
384 * Status code (400) indicating the request sent by the client was
385 * syntactically incorrect.
386 */
387
388 public static final int SC_BAD_REQUEST = 400;
389
390 /**
391 * Status code (401) indicating that the request requires HTTP
392 * authentication.
393 */
394
395 public static final int SC_UNAUTHORIZED = 401;
396
397 /**
398 * Status code (402) reserved for future use.
399 */
400
401 public static final int SC_PAYMENT_REQUIRED = 402;
402
403 /**
404 * Status code (403) indicating the server understood the request
405 * but refused to fulfill it.
406 */
407
408 public static final int SC_FORBIDDEN = 403;
409
410 /**
411 * Status code (404) indicating that the requested resource is not
412 * available.
413 */
414
415 public static final int SC_NOT_FOUND = 404;
416
417 /**
418 * Status code (405) indicating that the method specified in the
419 * <code><em>Request-Line</em></code> is not allowed for the resource
420 * identified by the <code><em>Request-URI</em></code>.
421 */
422
423 public static final int SC_METHOD_NOT_ALLOWED = 405;
424
425 /**
426 * Status code (406) indicating that the resource identified by the
427 * request is only capable of generating response entities which have
428 * content characteristics not acceptable according to the accept
429 * headerssent in the request.
430 */
431
432 public static final int SC_NOT_ACCEPTABLE = 406;
433
434 /**
435 * Status code (407) indicating that the client <em>MUST</em> first
436 * authenticate itself with the proxy.
437 */
438
439 public static final int SC_PROXY_AUTHENTICATION_REQUIRED = 407;
440
441 /**
442 * Status code (408) indicating that the client did not produce a
443 * requestwithin the time that the server was prepared to wait.
444 */
445
446 public static final int SC_REQUEST_TIMEOUT = 408;
447
448 /**
449 * Status code (409) indicating that the request could not be
450 * completed due to a conflict with the current state of the
451 * resource.
452 */
453
454 public static final int SC_CONFLICT = 409;
455
456 /**
457 * Status code (410) indicating that the resource is no longer
458 * available at the server and no forwarding address is known.
459 * This condition <em>SHOULD</em> be considered permanent.
460 */
461
462 public static final int SC_GONE = 410;
463
464 /**
465 * Status code (411) indicating that the request cannot be handled
466 * without a defined <code><em>Content-Length</em></code>.
467 */
468
469 public static final int SC_LENGTH_REQUIRED = 411;
470
471 /**
472 * Status code (412) indicating that the precondition given in one
473 * or more of the request-header fields evaluated to false when it
474 * was tested on the server.
475 */
476
477 public static final int SC_PRECONDITION_FAILED = 412;
478
479 /**
480 * Status code (413) indicating that the server is refusing to process
481 * the request because the request entity is larger than the server is
482 * willing or able to process.
483 */
484
485 public static final int SC_REQUEST_ENTITY_TOO_LARGE = 413;
486
487 /**
488 * Status code (414) indicating that the server is refusing to service
489 * the request because the <code><em>Request-URI</em></code> is longer
490 * than the server is willing to interpret.
491 */
492
493 public static final int SC_REQUEST_URI_TOO_LONG = 414;
494
495 /**
496 * Status code (415) indicating that the server is refusing to service
497 * the request because the entity of the request is in a format not
498 * supported by the requested resource for the requested method.
499 */
500
501 public static final int SC_UNSUPPORTED_MEDIA_TYPE = 415;
502
503 /**
504 * Status code (500) indicating an error inside the HTTP server
505 * which prevented it from fulfilling the request.
506 */
507
508 public static final int SC_INTERNAL_SERVER_ERROR = 500;
509
510 /**
511 * Status code (501) indicating the HTTP server does not support
512 * the functionality needed to fulfill the request.
513 */
514
515 public static final int SC_NOT_IMPLEMENTED = 501;
516
517 /**
518 * Status code (502) indicating that the HTTP server received an
519 * invalid response from a server it consulted when acting as a
520 * proxy or gateway.
521 */
522
523 public static final int SC_BAD_GATEWAY = 502;
524
525 /**
526 * Status code (503) indicating that the HTTP server is
527 * temporarily overloaded, and unable to handle the request.
528 */
529
530 public static final int SC_SERVICE_UNAVAILABLE = 503;
531
532 /**
533 * Status code (504) indicating that the server did not receive
534 * a timely response from the upstream server while acting as
535 * a gateway or proxy.
536 */
537
538 public static final int SC_GATEWAY_TIMEOUT = 504;
539
540 /**
541 * Status code (505) indicating that the server does not support
542 * or refuses to support the HTTP protocol version that was used
543 * in the request message.
544 */
545
546 public static final int SC_HTTP_VERSION_NOT_SUPPORTED = 505;
547}