모든 서블릿에 들어가야하는 코드 세 줄에 대한 설명
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
#response.setCharacterEncoding("UTF-8");
#request.setCharacterEncoding("UTF-8");
요청하고 응답받을때의 인코딩 타입은 UTF-8로. (한글이 깨질 때 체크하기)
톰캣 server.xml에서 URIEncoding="UTF-8" 지정하면 되지만 서버 설정 건드리는 것은 지양됨
#response.setContentType("text/html; charset=UTF-8");
- test/htm : 컨텐트 타입이 없을 경우, 브라우저는 타입을 자의적으로 해석함. (html 또는 text)
따라서 지정해주어야 모든 브라우저에서 동일하게 표시됨
- charset=UTF-8 : 전송한 컨텐츠의 타입을 UTF-8로 명시해 한글을 깨짐 없이 디코딩하도록 한다.
'JSP & Servlet' 카테고리의 다른 글
[Eclipse] html 파일명 변경 후 404 ERROR (0) | 2022.12.23 |
---|---|
<input type="submit">의 name / form method="post" (0) | 2022.12.20 |
Servlet filter (0) | 2022.12.19 |
Servlet과 WEB-INF 기초 (0) | 2022.12.18 |