본문 바로가기

프로그래밍/Spring & MyBatis

[Spring/Mybatis] 한글 깨짐 처리

참조

http://miconblog.com/tc/sohn/563

http://blog.naver.com/PostView.nhn?blogId=kobell9&logNo=90149920026

1. Spring 설정

web.xml 에 아래와 같이 Spring 에서 제공하는 filter를 설정해준다.

(POST를 한글처리를위한 설정)

<filter>

<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-mapping>

<filter-name>encodingFilter</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

servelt-context.xml 설정

<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->

<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<beans:property name="prefix" value="/WEB-INF/views/" />

<beans:property name="suffix" value=".jsp" />

<beans:property name="contentType" value="text/html; charset=UTF-8" />

</beans:bean>

2. Server 설정


Server.xml

(GET 한글 처리를 위한 설정)


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


<Connector port="8009" protocol="AJP/1.3" redirectPort="8443"URIEncoding="UTF-8"/>


3. jsp 설정

<%@ page session="false" pageEncoding="UTF-8"%>



4. Mybatis 입력시 한글깨짐

한글입력시깨짐문제 발생
jdbc.url=jdbc:mysql://localhost:3306/디비명?useUnicode=true&characterEncoding=utf8


5. @ResponseBody 응답시 한글깨짐

@RequestMapping(value = "/Act",produces="text/plain;charset=UTF-8")
@ResponseBody


6Eclipse설정

preference->general->workspace UTF-8 Setting

preference->web->CSS UTF-8 Setting

preference->web->HTML UTF-8 Setting

preference->web->JSP UTF-8 Setting



7. JavaScript 설정

GET으로 보낼때 encodeURI() 수행