-
스프링 Helloworld에서 글자 깨짐스프링 2022. 4. 14. 16:27
처음 스프링으로 프로젝트를 만들게 되면 아무런 설정이 안 되어 있는 상태이기 때문에
글자가 깨져 보인다.
해결방법
1. JSP파일에 인코딩 정보를 추가한다.
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="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>
2. 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>
위 셋팅을 web.xml에 추가.
(특히 forceEncoding 부분을 같이 넣어주면 각 JSP파일에 인코딩 부분을 추가하지 않아도 강제 인코딩이 적용됩니다.)
스프링이 아닌 단순 웹 프로젝트인 경우
server.xml
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="utf-8"/>
를 추가하여 한글 URL을 사용할 수 있습니다.
참고 블로그 출처: https://suyou.tistory.com/93 [수유산장]'스프링' 카테고리의 다른 글
스프링 404 에러 (0) 2022.04.26 ORA-00911 문자가 부적합합니다. 해결방법 (0) 2022.04.26 java.sql.SQLException: 부적합한 열 유형: 1111 (0) 2022.04.26 이메일 전송 오류 Mail server connection failed; nested exception is javax.mail.MessagingException: Could not convert socket to TLS; (0) 2022.04.22 스프링 레거시 프로젝트 기본 경로 (0) 2022.04.14