개발/JSP

[JSP] request 객체 연습 2

suniverse 2023. 1. 23. 23:52

✍ 로그인 화면 코드 작성

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
	<h1>로그인 화면</h1>
	<form action="test3_.jsp" method="post">
		<table border="1">
			<tr>
				<td>아이디</td>
				<td><input type="text" name="id" required="required"></td>
			</tr>
			<tr>
				<td>패스워드</td>
				<td><input type="password" name="passwd" required="required"></td>
			</tr>
			<tr>
				<td colspan="2">
				<input type="submit" value="로그인">
				</td>
			</tr>
		</table>
	</form>
</body>
</html>

✍ 객체 처리 응답페이지 코드

<%@ 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>
	<h1>응답 페이지</h1>
	<%
	String id = request.getParameter("id");
	String passwd = request.getParameter("passwd");
	%>
	
	<h3>아이디: <%=id %></h3>
	<h3>패스워드: <%=passwd %></h3>
</body>
</html>

test3.jsp 에서 로그인 버튼을 누르면 데이터가 전달되고

test3_.jsp 페이지에서 객체를 생성&처리하여 출력한다.

 


💻 test3.jsp 실행 화면

💻test3_.jsp 응답페이지 실행 화면

--> 이전페이지에서 입력한 아이디와 패스워드가 정상적으로 출력된 걸 알 수 있다.