[๊ตฌ๋์์นด๋ฐ๋ฏธ IT๊ตญ๋น์ง์] html์์ ๊ฐ์ฅ ์ค์ํ๋ค๊ณ ํ ์ ์๋ form ํ๊ทธ๋ฅผ ์ด์ฉํ์ฌ ํ์ด์ง๋ฅผ ๋ง๋ค์ด๋ณด์๋ค.
form ํ๊ทธ๋ ์ค๋ฌด์์ ๊ฐ์ฅ ๋ง์ด ์ฌ์ฉํ๊ณ , ํ์๊ฐ์
ํ์ด์ง ๋ฑ์ ๋ง๋ค ๋ ์ ์ฉํ๊ฒ ์ธ ์ ์๊ธฐ ๋๋ฌธ์ ์ ์์งํด๋๋ ๊ฒ์ด ์ค์ํ๋ค๊ณ ํ์
จ๋ค.
์ง๊ธ๊น์ง ๋ฐฐ์ด ๋ด์ฉ์ผ๋ก ์์ ๋ฅผ ๋ณด๊ณ ๋๊ฐ์ด ํ์ด์ง๋ฅผ ์นดํผํ๋ ์๊ฐ์ ๊ฐ์ก๋ค.
๐์์
๐์์ฑ
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>ํ์๊ฐ์
ํ์ด์ง</title>
<style>
.left {color:#8C8C8C; font-size:80%; font-weight:bold;}
</style>
</head>
<body>
<form action="">
<fieldset>
<legend>01 ๋ก๊ทธ์ธ ์ ๋ณด</legend>
<table>
<tr>
<td>
<img src="./check.jpg" width="15" height="15">
<span class="left">์ฌ์ฉ์ ID</span>
</td>
<td>
<input type="text" value="์๋ฌธ์ด๋ฆ๋ง์ฌ์ฉ">
<button type="submit">์ค๋ณตํ์ธ</button>
๋์ด์ฐ๊ธฐ ์๋ ์๋ฌธ์๋ฌธ์,์ซ์์กฐํฉ
</td>
</tr>
<tr>
<td>
<img src="./check.jpg" width="15" height="15">
<span class="left">๋น๋ฐ๋ฒํธ</span>
</td>
<td>
<input type="password">
๋์ด์ฐ๊ธฐ ์๋ ์๋ฌธ์๋ฌธ์,์ซ์์กฐํฉ
</td>
</tr>
<tr>
<td>
<img src="./check.jpg" width="15" height="15">
<span class="left">๋น๋ฐ๋ฒํธํ์ธ</span>
</td>
<td>
<input type="password">
๋น๋ฐ๋ฒํธ๋ฅผ ํ๋ฒ๋ ์
๋ ฅํด์ฃผ์ธ์
</td>
</tr>
</table>
</fieldset>
<fieldset>
<legend>02 ๊ฐ์ธ ์ ๋ณด</legend>
<table>
<tr>
<td>
<img src="./check.jpg" width="15" height="15">
<span class="left">์ด๋ฆ</span>
</td>
<td>
<input type="text">
</td>
</tr>
<tr>
<td>
<img src="./box.jpg" width="15" height="15">
<span class="left">์ฃผ๋ฏผ๋ฑ๋ก๋ฒํธ</span>
</td>
<td>
<input type="number">
-
<input type="password">
</td>
</tr>
<tr>
<td>
<img src="./box.jpg" width="15" height="15">
<span class="left">์๋
์์ผ</span>
</td>
<td>
<input type="number" style="width:70px;">๋
<input type="number" style="width:70px;">์
<input type="number" style="width:70px;">์ผ
<input type="radio" name="birthday">์๋ ฅ
<input type="radio" name="birthday">์๋ ฅ
</td>
</tr>
<tr>
<td>
<img src="./check.jpg" width="15" height="15">
<span class="left">์ฐ๋ฝ์ฒ</span>
</td>
<td>
<select style="width:90px;">
<option>==์ ํ==</option>
<option>010</option>
<option>02</option>
<option>032</option>
</select>
-
<input type="number" style="width:70px;">
-
<input type="number" style="width:70px;">
<input type="radio" name="number_type">์ํ
<input type="radio" name="number_type">์ง์ฅ
</td>
</tr>
<tr>
<td>
<img src="./check.jpg" width="15" height="15">
<span class="left">ํด๋์ ํ</span>
</td>
<td>
<input type="number" style="width:70px;">
-
<input type="number" style="width:70px;">
-
<input type="number" style="width:70px;">
</td>
</tr>
<tr>
<td>
<img src="./check.jpg" width="15" height="15">
<span class="left">E-mail ์ฃผ์</span>
</td>
<td>
<input type="email" value="example@example.com" style="width:400px;">
</td>
</tr>
<tr>
<td>
<img src="./check.jpg" width="15" height="15">
<span class="left" >์ฃผ์</span>
</td>
<td>
<input type="text" style="width:70px;">
-
<input type="text" style="width:70px;">
<button type="submit">์ฐํธ๋ฒํธ์ฐพ๊ธฐ</button>
<input type="radio" name="address_type">์ํ
<input type="radio" name="address_type">์ง์ฅ <br>
<input type="text" style="width:400px;"> <br>
<input type="text" style="width:400px;">
</td>
</tr>
</table>
</fieldset>
<fieldset>
<legend>03 ๊ธฐํ ์ ๋ณด</legend>
<table>
<tr>
<td>
<img src="./box.jpg" width="15" height="15">
<span class="left">์ง์
</span>
</td>
<td>
<select style="width:140px;">
<option>===์ ํํ์ธ์===</option>
<option>ํ์</option>
<option>์ง์ฅ์ธ</option>
<option>์์ฌ</option>
<option>์์ง๋์ด</option>
<option>์๊ฐ</option>
</select>
</td>
</tr>
<tr>
<td>
<img src="./box.jpg" width="15" height="15">
<span class="left">ํ์ฌ๋ช
(ํ๊ต)</span>
</td>
<td>
<input type="text">
<button type="submit">์ฐพ๊ธฐ</button>
<input type="radio" name="work_type">์ํ
<input type="radio" name="work_type">์ง์ฅ
</td>
</tr>
<tr>
<td>
<img src="./box.jpg" width="15" height="15">
<span class="left">์ฌ์
์๋ฒํธ</span>
</td>
<td>
<input type="number">
</td>
</tr>
<tr>
<td>
<img src="./box.jpg" width="15" height="15">
<span class="left">๋ถ์๋ช
(ํ๊ณผ)</span>
</td>
<td>
<input type="text">
</td>
</tr>
<tr>
<td>
<img src="./box.jpg" width="15" height="15">
<span class="left">์ง์(ํ๋
)</span>
</td>
<td>
<input type="text">
</td>
</tr>
<tr>
<td>
<img src="./box.jpg" width="15" height="15">
<span class="left">๊ด์ฌ๋ถ์ผ</span>
</td>
<td>
<select style="width:140px;">
<option>===์ ํํ์ธ์===</option>
<option>์ํ</option>
<option>๊ณตํ</option>
<option>๋ฌผ๋ฆฌํ</option>
<option>๊ฒฝ์ ํ</option>
<option>์ปดํจํฐ๊ณตํ</option>
</select>
</td>
</tr>
<tr>
<td>
<img src="./box.jpg" width="15" height="15">
<span class="left">TP์น์ง ์์ </span>
</td>
<td>
<input type="radio" name="TP">์์ ๋์
<input type="radio" name="TP">์์ ํ์ง์์
(TP์์ ์ ๊ณตํ๋ Webzine ์๋น์ค๋ฅผ ๋ฐ์๋ณด์๊ฒ ์ต๋๊น?)
</td>
</tr>
<tr>
<td>
<img src="./box.jpg" width="15" height="15">
<span class="left">ํํ์ด์ง์ฃผ์</span>
</td>
<td>
<input type="url" style="width:400px;">
</td>
</tr>
<tr>
<td>
<img src="./box.jpg" width="15" height="15">
<span class="left">์๊ธฐ์๊ฐ</span>
</td>
<td>
<textarea rows="2" cols="20"></textarea>
</td>
</tr>
</table>
</fieldset>
<br>
<fieldset>
<img src="./box.jpg" width="15" height="15">
<button type="submit">๊ฐ์
</button>
<button type="reset">์ทจ์</button>
</fieldset>
</form>
</body>
</html>
๐๊ฒฐ๊ณผ
โ๏ธ ๊ฐ์ ์
๋ง์ ๋ง๋๋ ค๊ณ ํ๋ ๋ง๋งํ ๋๋์ด ๋จผ์ ๋ค์๋ ๊ฒ ๊ฐ๋ค. ์์์ ๋ฐฐ์ด ๋ด์ฉ์ด ๊ฐ์๊ธฐ ์๊ฐ์ด ์๋๊ฑฐ๋, ์ํ๋๋๋ก ํ์ฉ์ ๋ชปํด์ ๋ต๋ตํ ๊ธฐ๋ถ์ด ๋ค์๊ณ ์๊ฐ๋ณด๋ค ์๊ฐ๋ ์ค๋ ๊ฑธ๋ ธ๋ค.๐ฐ ๊ทธ๋๋ ์ฐจ๊ทผ์ฐจ๊ทผ ๊ทธ๋ํ ํ๋ ์์ ๋ค์ ์ดํด๋ณด๋ฉด์ ์ฌ๋ฏธ๋ฅผ ์ฐพ์ผ๋ ค๊ณ ๋
ธ๋ ฅํ๋ค. ๋ค์ฌ์ฐ๊ธฐ, placeholder ์ฌ์ฉํ๊ธฐ, table ๋ง๋ค๊ธฐ, ํด๋์ค์ ์์ด๋ ๋ถ์ฌํ๊ธฐ๋ฅผ ์กฐ๊ธ ๋ ์ฐ์ตํด์ผ๊ฒ ๋ค๊ณ ๋๊ผ๋ค.๐ช ์ ์ถ ํ ๋ค๋ฅธ ์ฌ๋๋ค์ ์ฝ๋๋ฅผ ๋ณด๋ฉด์ ๋ง์ด ๋ฐฐ์ ๋ค.โ๏ธ ๋ด๊ฐ ์ด๋ค ์ ์ด ๋ถ์กฑํ์ง ๋๋ฌด๋ ์ ๋๊ปด์ ธ์ ์กฐ๊ธ ์ฐ์ธํด์ง๊ธฐ๋ ํ๋ค.๐ฅฒ ํ์ง๋ง ์์ง ์ด๋ฐ์ด๋ ๋ถ์กฑํ ๊ฒ์ ๋น์ฐํ๋ค!!๐ง ํ๋์ฉ ํ๋์ฉ ํด๋๊ฐ๋ค๋ณด๋ฉด ๋๋ ๋ฅ์ํ๊ฒ ํด๋ผ ์ ์์๊ฑฐ๋ผ๊ณ ์๊ฐํ๋ค. ํ์ดํ
!!! ๐๐
<!DOCTYPE html>
<html>
<!-- ๋ฉํ์ ๋ณด (ํ์ด์ง์ ์ถ๋ ฅx) -->
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<!-- ์ปจํ
์ธ (์ฐ์ถ๋ฌผ,์นํ์ด์ง์ ์ถ๋ ฅ)-->
<body>
<!-- ๋ค๋ฅธ ํ์ด์ง๋ฅผ ์์ฒญ(์๊ตฌ์ฌํญ ๊ฐ์ด ํ์) ํ๋ ๋ฐฉ๋ฒ 2๊ฐ์ง -->
<a href="./action1.html?๋=100">action1</a>
<form action="./action1.html" method="post">
<input type="text" name="๋" value="100">
<button type="submit">action1</button>
</form>
<!-- ์ ๋ ์ฝ๋๋ ๊ฒฐ๊ตญ ๊ฐ์ ๋ด์ฉ (๋=100) -->
<!-- ํ์ง๋ง aํ๊ทธ๋ ๊ฐ์ด ๊ณ ์ ๋์ด ์์ ์์ ๋ถ๊ฐ
form ํ๊ทธ๋ input ํ๊ทธ๋ฅผ ์ด์ฉํ์ฌ ๊ฐ์ ์ง์ ์
๋ ฅ ๋ฐ ์์ ๊ฐ๋ฅํจ
๊ทธ๋ฌ๋ฏ๋ก ๋จ์ ํ์ด์ง๋ฅผ ์์ฒญํ๋ ๊ฒฝ์ฐ๋ ๊ตณ์ด formํ๊ทธ๋ฅผ ์ด์ฉํ ํ์ ์์ (์ ์ ์ธ ๋ฐฉ๋ฒ)
์
๋ ฅ ๊ฐ์ ๋ฐ๋ผ ๋ค๋ฅธ ํ์ด์ง๋ฅผ ์์ฒญํ๋ ๊ฒฝ์ฐ(์นํ๋ก๊ทธ๋จ)์ formํ๊ทธ๋ฅผ ์ด์ฉ (๋์ ์ธ ๋ฐฉ๋ฒ) -->
<!-- form ํ๊ทธ์ ์ฅ์ : ๊ฐ์ ์จ๊ธธ ์ ์์! ๋๋ถ๋ถ ๊ฐ์ ์จ๊ธธ ์ ์๊ฒํจ (post ๋ฐฉ์)
๋ํดํธ ๊ฐ์ ๊ฐ์ด ๊ณต๊ฐ๋จ (get ๋ฐฉ์) -->
</body>
</html>
๋ค๋ฅธ ํ์ด์ง๋ฅผ ์์ฒญํ๋ ๋ฐฉ๋ฒ์ 2๊ฐ์ง๊ฐ ์๋ค.
ํ์ง๋ง ์ ๋ ฅํ ๊ฐ์ ๋ฐ๋ผ ๋ค๋ฅธ ํ์ด์ง๋ฅผ ์์ฒญํ๊ธฐ ์ํด์๋ a ํ๊ทธ๊ฐ ์๋ form action ํ๊ทธ๋ฅผ ์ด์ฉํด์ผ ํ๋ค.
๋ํ form action ํ๊ทธ๋ ์ ๋ ฅํ ๊ฐ์ ์จ๊ธธ ์ ์๋ค.
์ฆ, form action ํ๊ทธ๋ ์ฌ์ฉ์๊ฐ ๊ฐ์ ๋ณ๊ฒฝํ ์ ์๊ณ , ์
๋ ฅํ ๊ฐ์ ์จ๊ธธ ์ ์๋ค๋ 2๊ฐ์ง ์ฅ์ ์ด ์๋ ๊ฒ์ด๋ค.
readonly๋ ๋ง๊ทธ๋๋ก ์ฝ๊ธฐ์ ์ฉ, ์์ ์ด ๋ถ๊ฐ๋ฅํ๋ค.
disabled๋ ์์ ์ด ๋ถ๊ฐ๋ฅํ๋ค. button์ด๋ color ๊ฐ์ด '์ฝ๋ ๊ฒ'์ด ์๋ ๊ฐ์ ์์ ํ์ง ๋ชปํ๊ฒ ํ ๋ ์ฌ์ฉํ ์ ์๋ค.
๐์์ฑ
<form>
<label for="fname">First name:</label><br>
<input type="text" id="fname" name="fname" value="John" readonly="readonly"><br>
<!-- name์ ํค, value๋ ๊ฐ -->
<label for="lname">Last name:</label><br>
<input type="text" id="lname" name="lname" value="Doe"><br>
<button type="button">enable</button>
<button type="button" disabled="disabled">disabled</button>
</form>
๐๊ฒฐ๊ณผ
Last name์ ์์ ์ด ๊ฐ๋ฅํ๊ณ , disabled ๋ฒํผ์ ๋๋ฅผ ์ ์๋ค.
form action ํ๊ทธ๋ฅผ ์ฌ์ฉ
์ด๋ button type="submit" ์ ๊ฐ์ด ์ฌ์ฉํ๋ฉฐ
๋ฒํผ์ ํผ ์์ ์์ด์ผํจ
๋ฒํผ์ ๋๋ฅด๋ฉด ํผ ์์ ์๋ ๊ฐ๋ค์ด ์ ์ก๋๋ฉฐ ๋ง๋ ํ์ด์ง๊ฐ ๋์ด
(= ์นํ๋ก๊ทธ๋จ)
<form action="./guest.jsp">
<button type="submit">guest.jsp์ก์
์ผ๋ก</button>
<button type="submit" formaction="./admin.jsp">admin.jsp์ก์
์ผ๋ก</button>
</form>
๐html ์์ฑ
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>inputForm</title>
<style>
table, th, td {border: 1px solid #343434;}
</style>
</head>
<body>
<h1>๊ธ์
๋ ฅ</h1>
<form action="./inputAction.jsp" method="get" target="_blank">
<!-- ํค๊ฐ์ ๋ฐ์์ ์ฒ๋ฆฌํ๊ธฐ ์ํด์๋ ์นํ์ด์ง(html)๊ฐ ์๋ ์นํ๋ก๊ทธ๋จ(jsp)๊ฐ
form action์ ์ ์ฅ๋์ด ์์ด์ผ ํ๋ค -->
<table>
<tr>
<th>์์ด๋</th>
<td><input type="text" name="id" value=""></td>
</tr>
<tr>
<th>๋น๋ฐ๋ฒํธ</th>
<td><input type="password" name="pw" value=""></td>
</tr>
<tr>
<th>์ฑ๋ณ</th>
<td>
<input type="radio" name="gender" value="๋จ">๋จ
<input type="radio" name="gender" value="์ฌ">์ฌ
</td>
</tr>
<tr>
<th>๊ตญ์ </th>
<td>
<select name="country">
<option value="">์ ํํ์ธ์</option>
<option value="๋ํ๋ฏผ๊ตญ">๋ํ๋ฏผ๊ตญ</option>
<option value="๋ฏธ๊ตญ">๋ฏธ๊ตญ</option>
</select>
</td>
</tr>
<tr>
<th>์ข์ํ๋ ์์</th>
<td>
<input type="color" name="likeColor">
</td>
</tr>
<tr>
<th colspan="2"><button type="submit">์
๋ ฅ</button></th>
</tr>
</table>
</form>
</body>
</html>
๐๊ฒฐ๊ณผ
์ด๊ณณ์ ์ฌ์ฉ์๊ฐ ์ง์ ๊ฐ์ ์
๋ ฅํ ๋ค ์
๋ ฅ
๋ฒํผ์ ๋๋ฅด๋ฉด, ํด๋น ๊ฐ์ ๋ง๋ jsp ํ์ด์ง๊ฐ ์์ฒญ๋๋ค.
๐jsp ์์ฑ
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>inputAction</title>
</head>
<body>
<%
String id = request.getParameter("id"); // ํค id์ ๊ฐ์ ๋ถ๋ฌ์์ ๋ณ์ id์ ์ ์ฅ
String pw = request.getParameter("pw");
String gender = request.getParameter("gender");
String country = request.getParameter("country");
String likeColor = request.getParameter("likeColor");
%>
<h1>์ถ๋ ฅ</h1>
<table>
<tr>
<th>์์ด๋</th>
<td> <%
out.print(id); // id์ ๊ฐ์ ์ถ๋ ฅ
%> </td>
</tr>
<tr>
<th>๋น๋ฐ๋ฒํธ</th>
<td><input type="password" value="<%=pw%>" readonly="readonly"></td>
</tr>
<tr>
<th>์ฑ๋ณ</th>
<td><%=gender%></td> <!-- gender์ ๊ฐ์ ์ถ๋ ฅ, ๋ ์ถ์ฝ๋ ๋ฒ์ -->
</tr>
<tr>
<th>๊ตญ์ </th>
<td><%=country%></td>
</tr>
<tr>
<th>์ข์ํ๋ ์์</th>
<td>
<input type="color" value="<%=likeColor%>" disabled="disabled">
<!-- ์์์ "์ฝ๋๊ฒ"์ด ์๋๊ธฐ ๋๋ฌธ์ readonly๊ฐ ์๋๋ผ disabled๋ฅผ ์ฌ์ฉ -->
</td>
</tr>
</table>
</body>
</html>
๐๊ฒฐ๊ณผ
readonly์ disabled๋ฅผ ์ฌ์ฉํ๊ธฐ ๋๋ฌธ์ ํด๋น ํ์ด์ง์์๋ ๊ฐ ์์ ์ด ๋ถ๊ฐ๋ฅํ๋ค.