달력

52024  이전 다음

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

'jsp 한글처리'에 해당되는 글 2건

  1. 2013.09.30 Response 구간 정리
  2. 2013.09.30 JSP,Servlet에서 한글 문제를 피하려면..

Response객체는 브라우저에 전달되는 HTML 결과 생성할 때 사용된다. Response객체의 Encoding CharterSet에 따라서 브라우저에서 출력되는 한글이 깨져보일수 있으므로 주위를 해야 한다. 하지만 걱정할 필요는 없다.
아래 제시되는 3가지 방법중 한 가지만 제대로 해도 한글 출력에 문제가 없다.
 

q
Response Charset에 따라서 출력되는 HTML Bodycharset에 영향을 미치게 된다.
qCharter set을 명시적으로 지정하라.
¤대략 3가지 방법으로 설정 가능하며 같은 효과가 있다.
1.Page 설정 통해서 설정
¡<%@ page pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
¡pageEncoding 생략시 charset에 따라서 Page Encoding
2.함수 호출 1
Response.setCharacterEncoding(“UTF-8”);
Response.setContentType("text/html");
3.함수 호출 2
Response.setContentType("text/html;charset=UTF-8");
¤방법 1,2,3 중복해서 호출될 경우, 마지막 호출된 값이 유효하다.
¤하지만 PrintWriter pw = response.getWriter(); 함수 호출 이후에는 setCharacterEncoding(), setContentType() 함수가 호출되어도 무시된다.  
q명시적으로 Charset을 설정하지 않았다면 아래 단계로 디폴트 값 설정 됨
1.HTTP RequestContent-Language 참조
2.<locale-encoding-mapping-list> 정보를 web.xml에서 찾는다.
3.ISO-8859-1 을 사용한다.

qSRV.5.4 Response data Encoding ( servlet-2_5-mrel2-spec.pdf 에서 발췌 )

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
Posted by 행복한삶~!!
|

한글 처리에 영향을 주는 곳

10여군대 이상의 곳에서 Encoding 관련 정보들이 있고, 한글 처리에 영향을 미칠수 있다. 
client 부터 WAS까지, WAS에서 DB 및 외부 I/O처리, 다시 WAS에서 Client까지 전 구간을 완벽하게 이해하는것은 어려운 일일수 있지만 몇가지만 정확하게 알고 있으면 한글 깨지는 문제는 피 할수 있다.
특별히 빨간색으로 표기된 부분의 환경설정이 중요하다.

한글 문제를 피하려면?

q몇 가지 환경설정만 잘하면된다.
¤전체 브라우징 과정을 살펴보면 많은 과정을 거치면서 10여군대 이상의 encoding관련 설정에 영향을 받는다. 모든 과정을 완벽히 이해하는것은 힘들지만 몇 가지 환경설정 및 핵심 구간의 동작을 이해하면 한글 문제를 할 수 있다.
¤필수 환경 설정
¤WAS JVM 설정
¤HTML Meta Tag
¤JSP 페이 설정
¤Servlet Response/Request 설정
¤DB 언어 설정
¤3가지 구간의 세부 동작을 이해하자!
¤브라우저부터 Request 객체까지
¡Static Page 호출 Form 데이터 수신 과정 이해
¤Java 언어에서의 Encoding 이해 및 외부 I/OEncoding 이해
¤Response 객체에서 Encoding 이해
q언어 처리는 크게 2가지 상황이 있다.
¤한글과 영어만 제대로 나오면 되는 경우 ( 다국어 처리를 고려하지 않음 )
¤한국어,중국어,일본어, 힌두어 등 다국어를 동시에 처리해야 하는 경우.

    한글과 영어만 고려한 환경설정 ( 다국어 처리를 고려하지 않음 )

qWAS JVM 설정
¤file.encoding=ms949, client.encoding.override=ms949
qHTML Meta Tag설정
¤<meta http-equiv="Content-Type" content="text/html; charset=euc-kr">
qJSP 페이지 설정
¤<%@ page pageEncoding=“ms949contentType="text/html;charset=ms949" %>
pageEncoding 생략시 charset 값으로 pageEncoding )
qServlet Response/Request 설정
¤HTTP 요청의 인코딩 지정 ( client.encoding.override가 정의되어 있다면 생략해도 됨 )
¤request.setCharacterEncoding(“ms949”);
¤HTTP 응답의 인코딩 지정
¤response.setContentType("text/html; charset=ms949"); or
response.setCharacterEncoding(“ms949");
q빨간색으로 표기된 ms949대신 euc-kr을 사용하면 euc-kr의 문제인 현대한글 중 2350자만 표현 가능한 문제가 발생한다. (,펲등의 한글이 깨짐) 그래서 euc-kr 대신 ms949를 사용하는것이 바람직하다. 
ms949가 비록 ms에서 만든 환영받지못한 Charter Set이지만, 오라클 DB, JAVA, 많은 WAS에서 대부분 지원하고 있는 표준의 역할을 하고 있다. ( 물론 unicode를 사용하지 않는 경우에 한해겠지만.. )
¤오라클도 ms949를 지원하므로 ms949 로 설정해야 현대한글이 모두 표현된다.
¤Html의 경우 charset=euc-kr로 을 줘도 브라우저에서 현대한글이 정상적으로 출력된다.
 
    다국어를 지원해야 하는 경우의 환경설정
q하나의 페이지에서 다국어를 입력,출력해야 한다면 모든 설정을 UTF-8로 통일시켜야 한다.
qWAS JVM 설정
¤file.encoding=UTF-8, client.encoding.override=UTF-8
qHTML 설정
¤<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
qJSP 페이지
¤<%@ page pageEncoding=“UTF-8" %> ( 생략가능, 생략시 charset 값으로 pageEncoding )
¤<%@ page contentType="text/html;charset=UTF-8" %>
qServlet 설정
¤HTTP 요청의 인코딩 지정
¤request.setCharacterEncoding(“UTF-8”);
¤HTTP 응답의 인코딩 지정
¤response.setContentType("text/html; charset=UTF-8"); or
response.setCharacterEncoding(“UTF-8");
qDBMS
¤DBMS 설정값도 UTF-8로 설정해야 한다

'그외 주제들 > 한글처리' 카테고리의 다른 글

Response 구간 정리  (0) 2013.09.30
Request 구간 정리  (0) 2013.09.30
Unicode ( 유니코드 )  (0) 2013.09.30
문자셋과 인코딩  (0) 2013.09.30
Character-Set & Encoding이란?  (0) 2013.09.30
Posted by 행복한삶~!!
|