티스토리 뷰

Request 내장 객체

 

- 반환 형태(Return type) : javax.servlet.http.HttpServletRequest

- 객체 설명 : 웹 브라우저의 요청 정보를 저장하고 있는 객체

 

메인 로그인 페이지 (RequestLogin.jsp)
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>

	<center>
		<h2>로그인 페이지</h2>
		<form action="RequestLoginProc.jsp" method="post">
			<table width="400" border="1">
				<tr height="60">
					<td align="center" width="150">아이디</td>
					<td align="center" width="250">
						<input type="text" name="id">
					</td>
				</tr>
				<tr height="60">
					<td align="center" width="150">패스워드</td>
					<td align="center" width="250">
						<input type="password" name="pass">
					</td>
				</tr>
				<tr height="60">
					<td colspan="2" align="center">
						<input type="submit" value="전송">
					</td>
				</tr>
			</table>
		</form>
	</center>
	
</body>
</html>

RequestLogin.jsp

 

로그인 정보를 받아 표시해주는 페이지 (RequestLoginProc.jsp)
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>

	<!-- RequestLogin.jsp에서 넘어온 아이디와 패스워드를 읽어들임  -->
	
	<%
	// 사용자 정보가 저장되어 있는 객체 request의 getParameter()를 이용해서 사용자의 정보를 추출
	// getParameter()는 String 자료형으로 값을 return하기 때문에 String 변수로 데이터를 받음
	String id = request.getParameter("id");
	String pass = request.getParameter("pass");
	%>
	
	<h2>
	당신의 아이디는 <%= id %> 이고 패스워드는 <%= pass %> 입니다.
	</h2>
	
	<a href="RequestForward.jsp">다음 페이지</a>

</body>
</html>

RequestLoginProc.jsp

 

Request 내장 객체의 범위를 벗어나는 다음 페이지 (RequestForward.jsp)
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>

	<!-- RequestLoginProc.jsp에서 넘어온 페이지  -->
	
	<%
	String id = request.getParameter("id");
	String pass = request.getParameter("pass");
	%>
	
	<!-- 이전 페이지에서 넘겨준 것이 없기 때문에 아이디와 패스워드가 표시되지 않음 -->
	
	<h2>
	RequestForward 페이지입니다.<br>
	당신의 아이디는 <%= id %> 이고 패스워드는 <%= pass %> 입니다.
	</h2>
	
</body>
</html>

RequestForward.jsp

 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/04   »
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30
글 보관함