Showing posts with label 한글. Show all posts
Showing posts with label 한글. Show all posts

2009-01-20

아파치 톰켓 6.0 한글 처리

아파치 톰켓 6.0에서 한글 처리 설정을 하는 방법은 다음과 같다. UTF-8을 사용하는 것으로 가정한다.


1. GET

${catalina.base}/conf/server.xml 파일에서 Connector 태그에 URIEncoding 속성을 설정한다.

<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8"/>

${catalina.base}는 톰켓을 설치한 디렉토리를 의미한다.


2. POST

서블릿 필터를 이용해서 javax.servlet.ServletRequest 객체의 setCharacterEncoding 메소드를 호출한다.

request.setCharacterEncoding("UTF-8");

* ServletRequest 객체의 getParameter 메소드를 호출하기 전에 setCharacterEncoding 메소드를 호출해야 한다.


3. Content Type


javax.servlet.ServletResponse 객체의 setContentType 메소드로 content-type을 지정한다.

response.setContentType("text/html; charset=UTF-8");

JSP에서 page 선언부로 설정할 수도 있다.

<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>

JSP 컴파일과 관련된 pageEncoding 속성도 설정한다.


4. HTML

<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>

meta 태그는 title 태그 앞에 있어야 한다.


5. 참고 자료



2004-11-06

자바에서 한글 처리

1. ISO-8859-1에서 KSC5601로

String before = ...
String after = new String(before.getBytes("8859_1"),"KSC5601");


2. properties 파일에서 한글 읽기
 
(1) 1. 번 방식 사용
 
(2) native2ascii 도구 사용

native2ascii Before.poroperties After.properties

 
3. 주의 사항
 
(1) 이클립스에서 properties 파일 관리
 
속성에서 encoding을 MS949로 변경