한 WAS 서버에서 UTF-8 과 EUC-KR 둘다 지원하기..

한 웹서버에 UTF-8과 EUC-KR 을 같이 사용할 수 있는 TIP이 있긴 합니다…실제로 사용하고 있으나, 테스트는 꼭 해보세요.. 
사용환경은 리눅스(CENTOS)+APACH+TOMCAT+SPRING2.5 

web.xml 에서 필터를 추가해주는데요 UTF-8용과 EUC-KR 둘다 필터를 추가해줍니다. 

<filter> 
<display-name>encodingFilter</display-name><filter-name>encodingFilter</filter-name> 
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> 
<init-param><param-name>encoding</param-name><param-value>UTF-8</param-value> 
</init-param> 
</filter> 

<filter> 
<display-name>euc_kr_encodingFilter</display-name><filter-name>euc_kr_encodingFilter</filter-name> 
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> 
<init-param><param-name>encoding</param-name><param-value>EUC-KR</param-value></init-param> 
</filter> 


<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>euc_kr_encodingFilter</filter-name>
<url-pattern>*.do2</url-pattern>
</filter-mapping>

<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.do2</url-pattern>
</servlet-mapping>

 

 


그리고 톰캣디렉토리/conf/server.xml 에 보시면 connector 부분도 2개로 나눠 주셔야 합니다. 
<Connector port=”18009″ URIEncoding=”UTF-8″ maxThreads=”200″ minSpareThreads=”64″ maxSpareThreads=”150″ connectionTimeout=”10000″ acceptCount=”100″ 
enableLookups=”false” redirectPort=”8443″ protocol=”AJP/1.3″ /> 
<Connector port=”18010″ URIEncoding=”EUC-KR” maxThreads=”350″ minSpareThreads=”150″ maxSpareThreads=”300″ connectionTimeout=”10000″ acceptCount=”100″ 
enableLookups=”false” redirectPort=”8443″ protocol=”AJP/1.3″ /> 

 

이런 다음

 

로직에 의해서

response.setContentType(“text/html; charset=UTF-8”); 과

response.setContentType(“text/html; charset=EUC-KR”); 로 결과 뿌려 주기..

 

이렇게 하면 한 서버에서 다 된다…