Spring 인코딩 설정 - 한글 깨짐 해결 방법

CODEDRAGON Development/Spring

반응형

 

 

Spring 인코딩 설정 - 한글 깨짐 해결 방법

·         해결방법 1 - JSP file

·         해결방법 2 - web.xml

 


 

 

 

해결방법 1 - JSP file

 

JSP파일을 UTF-8로 만듭니다.

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

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

<%@ page session="false" %>

<html>

<head>

<title>Home</title>

</head>

<body>

<h1>

Hello world! 

</h1>

 

<P>  The time on the server is ${serverTime}. </P>

 

<a href="/ch06ex02/board/write">write.jsp</a><p>

</body>

</html>

 

 

소스 파일이 열려진 상태에서 Alt + Enter 단축키로 실행하여

파일의 저장 속성을 UTF-8로 설정합니다.

Alt + Enter


  

 

 

해결방법 2 - web.xml

web.xml 파일에 filter 요소를 추가합니다.

 

/ch06ex01/src/main/webapp/WEB-INF/web.xml

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

<init-param>

<param-name>forceEncoding</param-name> 

<param-value>true</param-value>

</init-param>

</filter>   

 

<filter-mapping>

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

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

</filter-mapping>

 

 

반응형