시작
[JSP][Form Tag][Action] 데이터 전송 및 받기
굿밤
2021. 10. 27. 19:55
보내는 파일 : form.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!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=UTF-8">
</head>
<body>
<form action="./result.jsp" method="post"> <!-- 전송 경로, 전송 타입 지정 -->
<table border="1">
<tr>
<th>이름</th>
<td><input type="text" id="name" name="name"></td>
</tr>
<tr>
<th>번호</th>
<td><input type="text" id="ph_number" name="ph_number"></td>
</tr>
<tr>
<th>주소</th>
<td><input type="text" id="address" name="address"></td>
</tr>
</table>
<br>
<input type="submit" value="제출">
</form>
</body>
</html>
받는 파일 : result.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
request.setCharacterEncoding("utf-8");
String name = request.getParameter("name");
String ph_number = request.getParameter("ph_number");
String address = request.getParameter("address");
%>
<!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=UTF-8">
</head>
<body>
<table border="1">
<tr>
<th>[확인] 이름</th>
<td><%=name%></td>
</tr>
<tr>
<th>[확인] 번호</th>
<td><%=ph_number%></td>
</tr>
<tr>
<th>[확인] 주소</th>
<td><%=address%></td>
</tr>
</table>
</body>
</html>
입력 후 "제출" 클릭
결과