본문 바로가기

IT/이클립스 오류내역

[UTF-8] JSP 페이지에서 한글 깨짐 방지

[UTF-8] JSP 페이지에서 한글 깨짐 방지
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<!-- UTF-8 설정 시작 -->
<!--
한국 컴퓨터에서 serverTime은
한글이 포함되어 깨지므로
이 페이지는 utf-8로
인코딩되어있음을 알려주어야 하므로
아래와 같이 작성.
-->
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!-- UTF-8 설정 종료 -->
<html>
<head>
<meta charset="UTF-8" />
<title>Home</title>
</head>
<body>
<h1>Hello world!</h1>
<P>The time on the server is ${serverTime}.</P>
</body>
</html>
#####################################################################################################
<!--
web.xml에서
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
이거 바로 밑에 아래 filter와 filter-mapping 삽입
-->
<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>*.do</url-pattern>
</filter-mapping>