el_test1.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>el_test1.jsp</title>
</head>
<body>
<%--
jsp 내장객체
pageScope, requestScope, sessionScope, applicationScope
session.getAttribute("id") => ${sessionScope.id}
xxxScope는 생략가능 : 생략 시 작은 범위에서 큰 범위 순으로 자동 검색
${id} : page -> request -> session -> application
파라미터 값 : request.getParameter("id") -> $(param.id)
쿠키 값: $(cookie.id)
--%>
<%
session.setAttribute("id", "hong"); 세션에 id속성의 hong이라는 속성값을 저장
response.sendRedirect("el_test2.jsp"); el_test2로 넘어감
%>
</body>
</html>
el_test2.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>
세션에 저장된 정보: ${sessionScope.id}<br> //el_test1에서 세션에 저장한 id속성의 값을 불러옴
영역 생략 : ${id} // xxxScope는 생략가능
<hr>
<form action="el_test3.jsp" method="post"> // 밑의 submit을 하면 el_test3.jsp로 제어됨
<table border="1">
<tr>
<th>아이디</th>
<td><input type="text" name="id"></td>
</tr>
<tr>
<th>패스워드</th>
<td><input type="password" name="pw"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="확인"/></td>
</tr>
</table>
</form>
</body>
</html>
el_test3.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>el_test3.jsp</title>
</head>
<body>
아이디: ${param.id}<br> //el_test2에서 submit한 아이디 불러옴
패스워드: ${param.pw} //el_test2에서 submit한 패스워드 불러옴
</body>
</html>
'JSP' 카테고리의 다른 글
servlet(서블릿) 정리 예제 2 (1) | 2023.09.12 |
---|---|
servlet(서블릿) 정리 예제1 (0) | 2023.09.12 |
EL 정리 예제 1 (0) | 2023.09.11 |
JSTL 정리 예제 (0) | 2023.09.11 |
세션(session) 개요 (0) | 2021.01.16 |
댓글