Intellij JSP - Get/Post/Service 한글 깨짐 해결
less than 1 minute read
Get/Post/Service 한글 깨짐 해결
-
html/JSP -> JSP
-
Get 방식
-
page contentType 부분에 charset=UTF-8 추가
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
-
스크립틀릿에서 charset을 UTF-8로 지정
<% response.setCharacterEncoding("utf-8"); %>
-
Post 방식
-
지시자와 스크립틀릿 사용
<%@ page contentType="text/html;charset=UTF-8" language="java" %> <%--charset=UTF-8 추가--%>
...
<% response.setCharacterEncoding("utf-8"); %>
-
스크립틀릿만 사용
<%
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
%>
-
html/JSP -> Servlet
-
Get 방식
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws javax.servlet.ServletException, IOException {
// 추가
response.setContentType("text/html;charset=utf-8");
...
}
-
Post 방식
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws javax.servlet.ServletException, IOException {
// 추가
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
...
}
-
Service
-
Get 방식
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
super.service(req, resp);
resp.setContentType("text/html;charset=utf-8");
...
}
-
Post 방식
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
super.service(req, resp);
req.setCharacterEncoding("utf-8");
resp.setContentType("text/html;charset=utf-8");
...
}
-
Leave a comment