스프링 프로젝트를 톰캣서버 구동 후 접속을 하면 아래의 화면과 같이 ?? 이런식으로 한글이 깨지는걸 볼 수 있다.
인코딩을 UTF-8로 설정해주면 해결될 문제이니 3가지 방법을 적용하면 된다.
1. 이클립스 인코딩 설정
Window --> Preferences로 들어간다.
빨간 네모박스에 해당 메뉴들(CSS Files, HTML Files, JSP Files)의 Encoding 타입을 모두 ISO 10646/Unicode(UTF-8)로 바꿔준다.
General --> Workspace로 들어가 Text file encoding을 MS949가 아닌 UTF-8로 그림처럼 설정 해 준다.
2. Web.xml 설정
WEB-INF에 있는 web.xml을 열어준다. 그후 아래 소스를 복사해서 추가해준다.
<!-- UTF-8 인코딩 설정 -->
<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>
3. JSP파일 인코딩 설정
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!-- 해당 JSP의 인코딩을 UTF-8로 설정 -->
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<html>
<head>
<title>Home</title>
</head>
<body>
<h1>
Hello world!
</h1>
<P> The time on the server is ${serverTime}. </P>
</body>
</html>
맨 상단에 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> 이부분을 추가해 준다. 이부분은 해당 jsp의 인코딩을 이렇게 설정하겠다 라는 선언문이다.
설정을 다 한후 다시 서버를 재기동 다시 localhost:8080으로 접속하면 한글이 깨지는것 없이 정상 출력되는걸 볼 수 있다.
'Development > Spring 환경설정' 카테고리의 다른 글
[Spring] 스프링 개발(TomCat설치, 스프링 프로젝트 연동) (0) | 2020.10.10 |
---|---|
[Spring] 스프링 개발(STS설치, 프로젝트 생성) (0) | 2020.09.30 |
[Spring] 스프링 개발(개발환경 만들기 Eclipse, JDK 설치) (0) | 2020.09.29 |