09form.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="09requestETC.jsp" method="post">
<input type="text" name="hobby">์ทจ๋ฏธ
<input type="text" name="phone">ํฐ
<input type="number" name="age">๋์ด
<button type="submit">์ ์ถํ๊ธฐ</button>
<!-- form์์ ๋ฒํผ์ ๊ธฐ๋ณธ์ ์ผ๋ก submit -->
</form>
</body>
</html>
09requestETC.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>
<%request.setCharacterEncoding("utf-8"); %>
<!-- ์ด๋ฆ์ Encoding์ธ๋ฐ ํ๋ ์ผ์ ์ค์ ๋ก decoding
07form์์ '์ด๋ฆ'์ด๋ผ๋ ํ๋ผ๋ฏธํฐ๋ฅผ ๋๊ธธ ๋ ์ธ์ฝ๋ฉ๋ผ์ ๋์ด์ด
-->
<%
String hobby = request.getParameter("hobby");
String phone = request.getParameter("phone");
String age = request.getParameter("age");
int agePlus = Integer.parseInt(age) + 1;
%>
์ทจ๋ฏธ : <%=hobby %>
ํฐ : <%=phone %>
๋์ด : <%=age %>
1๋
๋ค ๋์ด : <%=agePlus %>
</body>
</html>
09form์์ <input type="number" name="age">์์ ์ฌ์ฉ์์๊ฒ ์ ๋ ฅ ๋ฐ์๊ฐ์ ์ซ์์ด๋ค.
ํ์ง๋ง ๊ทธ๊ฒ์ 09requestETC์์ String age = request.getParameter("age");๋ก Stringํ์ ์ผ๋ก ๋ฐ๊ฒ ๋๋ฉด 1๋ ๋ค ๋์ด๋ ์ถ๋ ฅํ ์ ์์ ๊ฒ์ด๋ค. String์ ๋ฌธ์์ด๊ธฐ ๋๋ฌธ์ ์ซ์์ฐ์ฐ์ด ๋์ง์๊ธฐ ๋๋ฌธ์ด๋ค. ๊ทธ๋ ๊ธฐ ๋๋ฌธ์ ํ์ ๋ณํ์ด ํ์ํด์ง๋ค.
int agePlus = Integer.parseInt(age) + 1; ์ด๋ฐ์์ผ๋ก ๋ง์ด๋ค.
'๐ Today I Learned(๊ฐ๋ฐ์ธ์ดํ์ต) > JSP' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
Day02(redirect) (0) | 2021.10.05 |
---|---|
Day02(aboutRequest) (0) | 2021.10.05 |
Day01(img) (0) | 2021.10.05 |
Day01(postํ์ ์ฌ์ฉ์ ์ค๋ฅํด๊ฒฐ) (0) | 2021.10.05 |
Day01(form, result) (0) | 2021.10.05 |