JSP/Servlet – JSTL <fmt:requestEncoding> 커스텀 액션 사용하기
기존에 <FORM> 엘리먼트의 POST 메소드를 통해 한글을 입력받기 위해서는 먼저request.setCharacterEncoding 메소드를 호출해야 했습니다.
하지만 jsp 페이지의 가독성을 위해 스크립팅 요소를 사용하지 않기로 했다면 <fmt:requestEncoding> 커스텀 액션을 사용하면 됩니다.
<fmt:requestEncoding value="euc-kr" />
예제를 통해 확인해 봅시다.
Input.html
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
<form action=InputResult.jsp method=POST>
한글 아이디를 입력하세요. <BR>
<input type=TEXT NAME=ID> <BR><BR>
<input type=SUBMIT VALUE='확인'>
</form>
</body>
</html>
InputResult.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<fmt:requestEncoding value="euc-kr"/><!-- 한글데이터를 -->
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
안녕하세요, ${param.ID }
</body>
</html>
실행 화면
입력 폼에 한글 아이디를 입력하면
잘나오는 것을 확인 할 수 있습니다.
'프로그래밍 > JSP Servlet' 카테고리의 다른 글
JSP/Servlet – 커스텀 액션에 body를 추가해보자 (0) | 2016.02.21 |
---|---|
JSP/Servlet – 동적 애트리뷰트를 지원하는 태그 파일 만들기 (0) | 2016.02.18 |
JSP/Servlet – 애트리뷰트를 지원하는 태그 파일 만들기 (0) | 2016.02.18 |
JSP/Servlet – 태그 파일을 이용해서 커스텀 액션 만드는 방법 (0) | 2016.02.14 |
JSP/Servlet – JSTL 프로퍼티 파일에 변수 포함하기 (0) | 2016.02.10 |
JSP/Servlet – JSTL <fmt:setBundle>과 <fmt:bundle> <fmt:message> 커스텀 액션 사용하기 (0) | 2016.02.03 |
JSP/Servlet – JSTL <fmt:setLocale> 커스텀 액션 사용하기 (0) | 2016.02.01 |
JSP/Servlet – JSTL <fmt:formatNumber> 커스텀 액션 사용하기 (0) | 2016.02.01 |