|
1 | 1 | /*
|
2 |
| - * Copyright (c) 1997, 2020 Oracle and/or its affiliates and others. |
| 2 | + * Copyright (c) 1997, 2021 Oracle and/or its affiliates and others. |
3 | 3 | * All rights reserved.
|
4 | 4 | * Copyright 2004 The Apache Software Foundation
|
5 | 5 | *
|
|
20 | 20 |
|
21 | 21 | import java.io.IOException;
|
22 | 22 | import java.io.PrintWriter;
|
| 23 | +import java.io.UnsupportedEncodingException; |
23 | 24 | import java.util.Locale;
|
24 | 25 |
|
25 | 26 | /**
|
@@ -134,23 +135,34 @@ public interface ServletResponse {
|
134 | 135 |
|
135 | 136 | /**
|
136 | 137 | * Sets the character encoding (MIME charset) of the response being sent to the client, for example, to UTF-8. If the
|
137 |
| - * response character encoding has already been set by the {@link ServletContext#setResponseCharacterEncoding}, |
138 |
| - * deployment descriptor, or using the setContentType() or setLocale() methods, the value set in this method overrides |
139 |
| - * any of those values. Calling {@link #setContentType} with the <code>String</code> of <code>text/html</code> and |
140 |
| - * calling this method with the <code>String</code> of <code>UTF-8</code> is equivalent with calling |
141 |
| - * <code>setContentType</code> with the <code>String</code> of <code>text/html; charset=UTF-8</code>. |
| 138 | + * response character encoding has already been set by {@link ServletContext#setResponseCharacterEncoding}, the |
| 139 | + * deployment descriptor, or using the {@link #setContentType} or {@link #setLocale} methods, the value set in this |
| 140 | + * method overrides all of those values. Calling {@link #setContentType} with the <code>String</code> of |
| 141 | + * <code>text/html</code> and calling this method with the <code>String</code> of <code>UTF-8</code> is equivalent to |
| 142 | + * calling {@link #setContentType} with the <code>String</code> of <code>text/html; charset=UTF-8</code>. |
142 | 143 | * <p>
|
143 | 144 | * This method can be called repeatedly to change the character encoding. This method has no effect if it is called
|
144 | 145 | * after <code>getWriter</code> has been called or after the response has been committed.
|
145 | 146 | * <p>
|
| 147 | + * If calling this method has an effect (as per the previous paragraph), calling this method with {@code null} clears |
| 148 | + * any character encoding set via a previous call to this method, {@link #setContentType} or {@link #setLocale} but does |
| 149 | + * not affect any default character encoding configured via {@link ServletContext#setResponseCharacterEncoding} or the |
| 150 | + * deployment descriptor. |
| 151 | + * <p> |
| 152 | + * If this method is called with an invalid or unrecognised character encoding, then a subsequent call to |
| 153 | + * {@link #getWriter()} will throw a {@link UnsupportedEncodingException}. Content for an unknown encoding can be sent |
| 154 | + * with the {@link ServletOutputStream} returned from {@link #getOutputStream()}. |
| 155 | + * <p> |
| 156 | + * Containers may choose to log calls to this method that use an invalid or unrecognised character encoding. |
| 157 | + * <p> |
146 | 158 | * Containers must communicate the character encoding used for the servlet response's writer to the client if the
|
147 | 159 | * protocol provides a way for doing so. In the case of HTTP, the character encoding is communicated as part of the
|
148 | 160 | * <code>Content-Type</code> header for text media types. Note that the character encoding cannot be communicated via
|
149 | 161 | * HTTP headers if the servlet does not specify a content type; however, it is still used to encode text written via the
|
150 | 162 | * servlet response's writer.
|
151 | 163 | *
|
152 | 164 | * @param charset a String specifying only the character set defined by IANA Character Sets
|
153 |
| - * (http://www.iana.org/assignments/character-sets) |
| 165 | + * (http://www.iana.org/assignments/character-sets) or {@code null} |
154 | 166 | *
|
155 | 167 | * @see #setContentType
|
156 | 168 | * @see #setLocale
|
@@ -182,17 +194,28 @@ public interface ServletResponse {
|
182 | 194 | * Sets the content type of the response being sent to the client, if the response has not been committed yet. The given
|
183 | 195 | * content type may include a character encoding specification, for example, <code>text/html;charset=UTF-8</code>. The
|
184 | 196 | * response's character encoding is only set from the given content type if this method is called before
|
185 |
| - * <code>getWriter</code> is called. |
| 197 | + * {@link #getWriter()} is called. |
186 | 198 | * <p>
|
187 | 199 | * This method may be called repeatedly to change content type and character encoding. This method has no effect if
|
188 | 200 | * called after the response has been committed. It does not set the response's character encoding if it is called after
|
189 | 201 | * <code>getWriter</code> has been called or after the response has been committed.
|
190 | 202 | * <p>
|
| 203 | + * If calling this method has an effect (as per the previous paragraph), calling this method with {@code null} clears |
| 204 | + * any content type set via a previous call to this method and clears any character encoding set via a previous call to |
| 205 | + * this method, {@link #setContentType} or {@link #setLocale} but does not affect any default character encoding |
| 206 | + * configured via {@link ServletContext#setResponseCharacterEncoding} or the deployment descriptor. |
| 207 | + * <p> |
| 208 | + * If this method is called with an invalid or unrecognised character encoding, then a subsequent call to |
| 209 | + * {@link #getWriter()} will throw a {@link UnsupportedEncodingException}. Content for an unknown encoding can be sent |
| 210 | + * with the {@link ServletOutputStream} returned from {@link #getOutputStream()}. |
| 211 | + * <p> |
| 212 | + * Containers may choose to log calls to this method that use an invalid or unrecognised character encoding. |
| 213 | + * <p> |
191 | 214 | * Containers must communicate the content type and the character encoding used for the servlet response's writer to the
|
192 | 215 | * client if the protocol provides a way for doing so. In the case of HTTP, the <code>Content-Type</code> header is
|
193 | 216 | * used.
|
194 | 217 | *
|
195 |
| - * @param type a <code>String</code> specifying the MIME type of the content |
| 218 | + * @param type a <code>String</code> specifying the MIME type of the content or {@code null} |
196 | 219 | *
|
197 | 220 | * @see #setLocale
|
198 | 221 | * @see #setCharacterEncoding
|
@@ -309,13 +332,17 @@ public interface ServletResponse {
|
309 | 332 | * {@link #setContentType} has been called with a charset specification, after {@link #setCharacterEncoding} has been
|
310 | 333 | * called, after <code>getWriter</code> has been called, or after the response has been committed.
|
311 | 334 | * <p>
|
| 335 | + * If calling this method has an effect on the locale (as per the previous paragraph), calling this method with |
| 336 | + * {@code null} clears any locale set via a previous call to this method. If calling this method has an effect on the |
| 337 | + * character encoding, calling this method with {@code null} clears the previously set character encoding. |
| 338 | + * <p> |
312 | 339 | * Containers must communicate the locale and the character encoding used for the servlet response's writer to the
|
313 | 340 | * client if the protocol provides a way for doing so. In the case of HTTP, the locale is communicated via the
|
314 | 341 | * <code>Content-Language</code> header, the character encoding as part of the <code>Content-Type</code> header for text
|
315 | 342 | * media types. Note that the character encoding cannot be communicated via HTTP headers if the servlet does not specify
|
316 | 343 | * a content type; however, it is still used to encode text written via the servlet response's writer.
|
317 | 344 | *
|
318 |
| - * @param loc the locale of the response |
| 345 | + * @param loc the locale of the response or {code @null} |
319 | 346 | *
|
320 | 347 | * @see #getLocale
|
321 | 348 | * @see #setContentType
|
|
0 commit comments