Response객체는 브라우저에 전달되는 HTML 결과 생성할 때 사용된다. Response객체의 Encoding CharterSet에 따라서 브라우저에서 출력되는 한글이 깨져보일수 있으므로 주위를 해야 한다. 하지만 걱정할 필요는 없다.
아래 제시되는 3가지 방법중 한 가지만 제대로 해도 한글 출력에 문제가 없다.
Response.setCharacterEncoding(“UTF-8”);
Response.setContentType("text/html");
Response.setContentType("text/html;charset=UTF-8");
Servlets should set the locale and the character encoding of a response. The locale is set using the ServletResponse.setLocale method. The method can be called repeatedly; but calls made after the response is committed have no effect. If the servlet does not set the locale before the page is committed, the container’s default locale is used to determine the response’s locale, but no specification is made for the communication with a client, such as Content-Language header in the case of HTTP.
<locale-encoding-mapping-list>
<locale-encoding-mapping>
<locale>ja</locale>
<encoding>Shift_JIS</encoding>
</locale-encoding-mapping>
</locale-encoding-mapping-list>
If the element does not exist or does not provide a mapping, setLocale uses a container dependent mapping. The setCharacterEncoding, setContentType, and setLocale methods can be called repeatedly to change the character encoding.
Calls made after the servlet response’s getWriter method has been called or after the response is committed have no effect on the character encoding. Calls to setContentType set the character encoding only if the given content type string
provides a value for the charset attribute. Calls to setLocale set the character encoding only if neither setCharacterEncoding nor setContentType has set the character encoding before.
If the servlet does not specify a character encoding before the getWriter method of the ServletResponse interface is called or the response is committed, the default ISO-8859-1 is used.
Containers must communicate the locale and the character encoding used for the servlet response’s writer to the client if the protocol in use provides a way for doing so. In the case of HTTP, the locale is communicated via the Content-Language header, the character encoding as part of the Content-Type header for text media types. Note that the character encoding cannot be communicated via
HTTP headers if the servlet does not specify a content type; however, it is still
used to encode text written via the servlet response’s writer.
'그외 주제들 > 한글처리' 카테고리의 다른 글
다양한 환경에서의 언어 설정 (0) | 2013.09.30 |
---|---|
자바에서 String 처리 (0) | 2013.09.30 |
Request 구간 정리 (0) | 2013.09.30 |
JSP,Servlet에서 한글 문제를 피하려면.. (0) | 2013.09.30 |
Unicode ( 유니코드 ) (0) | 2013.09.30 |