07form.jsp์ ์ฝ๋๋ด์ฉ
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="07encodingResult.jsp" method="post">
<input type="text" name="age" placeholder="๋์ด">
<input type="text" name="์ด๋ฆ" placeholder="์ด๋ฆ">
<input type="text" name="add" placeholder="์ฃผ์">
<input type="submit" value="์ ์ถ">
</form>
</body>
</html>
07encodingResult.jsp์ ์ฝ๋๋ด์ฉ (์์ ์ )
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
String age = request.getParameter("age");
String name = request.getParameter("์ด๋ฆ");
String add = request.getParameter("add");
%>
๋์ด : <%=age %> <br>
์ด๋ฆ : <%=name %> <br>
์ฃผ์ : <%=add %> <br>
</body>
</html>
ํฐ์บฃ์ ๊ธฐ๋ณธ์ ์ผ๋ก get๋ฐฉ์์ utf-8๋ก ํ๋ผ๋ฏธํฐ ์ธ์ฝ๋ฉ ํด์ค๋ค. contentType์ charset์ ์๋ฒ๊ฐ ๋ธ๋ผ์ฐ์ ๋ก ๋ณด๋ผ๋ ์ธ์ฝ๋ฉ ๋ฐฉ์์ด๊ณ , pageEncoding์ jsp ์์คํ์ผ ์ธ์ฝ๋ฉ ๋ฐฉ์์ด๋ค. ํ์ง๋ง 07form์์ action="post"๋ฐฉ์์ผ๋ก ๋ณด๋๊ธฐ๋๋ฌธ์ ๋ฐ์ดํฐ ์ ๋ ฅ ํ ์ ์ถ์์๋ ๋ฌธ์๊ฐ ์ฝํ์ง ์๋๋ค. ๋ฌธ์๋ฅผ ์ธ์ํ์ง ๋ชปํ๋ ๊ฒ์ด๋ค.
ํด๋น ๋ฌธ์ ๋ฅผ ํด๊ฒฐํ๋ ๋ฐฉ๋ฒ์ ์์ธ๋ก ๊ฐ๋จํ๋ค.
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%request.setCharacterEncoding("utf-8"); %>
<%
String age = request.getParameter("age");
String name = request.getParameter("์ด๋ฆ");
String add = request.getParameter("add");
%>
๋์ด : <%=age %> <br>
์ด๋ฆ : <%=name %> <br>
์ฃผ์ : <%=add %> <br>
</body>
</html>
<%request.setCharacterEncoding("utf-8"); %> ์ฝ๋๋ฅผ ์์ฑํด์ ๋ฌธ์ ํด๊ฒฐ !
โป์ด๋ฆ์ Encoding์ธ๋ฐ ํ๋ ์ผ์ ์ค์ ๋ก decoding์ ์ํํ๋ค. 07form์์ '์ด๋ฆ'์ด๋ผ๋ ํ๋ผ๋ฏธํฐ๋ฅผ ๋๊ธธ ๋ ์ธ์ฝ๋ฉ๋ผ์ ๋์ด์จ๋ค.
'๐ Today I Learned(๊ฐ๋ฐ์ธ์ดํ์ต) > JSP' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Day01(ํ์ ๋ณํ) (0) | 2021.10.05 |
---|---|
Day01(img) (0) | 2021.10.05 |
Day01(form, result) (0) | 2021.10.05 |
Day01(request) (0) | 2021.10.05 |
Day01(trimDirectiveWhitespaces, contentType) (0) | 2021.10.05 |