: 쿠키와 마찬가지로 서버와의 connection 관계를 유지하기 위해서 이용자의 정보를 저장하는 객체임.
세션의 특징
세션 관련 메서드
setAttribute()
==> 세션의 속성을 설정하는 메서드.
형식) session.setAttribute("id", "hong");
getAttribute()
==> 세션에서 데이터를 얻어올 때(세션의 속성을 사용할 때) 이용하는 메서드.
형식) String id = (String)session.getAttribute("id");
getAttributeNames()
==> 세션에 저장되어 있는 모든 데이터의 이름을 얻어올 때 사용하는 메서드.
removeAttribute()
==> 세션의 특정 데이터를 제거하는 메서드
형식) session.removeAttribute()
invalidate()
==> 세션의 모든 데이터를 삭제하는 메서드.
getId()
==> 자동 생성된 세션의 아이디를 얻어올 때 사용하는 메서드.
isNew()
==> 세션이 최초 생성되었는지 여부를 알고 싶은 경우 사용되는 메서드.
getMaxInactiveInterval()
==> 세션의 유효 시간을 얻어올 때 사용하는 메서드.
홈페이지에서 입력 받을 Ex01.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>
<div align = "center">
<form method = "post" action = "Ex01_01.jsp">
<p>아이디 : <input type = "text" name = "id"></p>
<p>비밀번호 : <input type = "password" name = "pwd"></p>
<input type = "submit" value = "로그인">
</form>
</div>
</body>
</html>

Ex01_01.jsp 생성
=============================코드=============================
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
String user_id = request.getParameter("id").trim();
String user_pwd = request.getParameter("pwd").trim();
String db_id = "hong";
String db_pwd = "1234";
if(user_id.equals(db_id)){
// 아이디가 존재하는 경우
if(user_pwd.equals(db_pwd)){
// 회원인 경우 ==> 메인 페이지로 이동 => 페이지 이동
// 특정한 정보를 넘겨주고 싶은 경우
session.setAttribute("Name", "홍길동");
session.setAttribute("Phone", "010-1111-1234");
// 페이지 이동
RequestDispatcher rd = request.getRequestDispatcher("Ex01_02.jsp");
rd.forward(request, response);
}else {
// 아이디는 일치하나 비밀번호는 다른 경우
System.out.println("비밀번호가 틀립니다!");
}
}else {
// 아이디가 테이블에 없거나 아니면 아이디가 잘못 입력된 경우
System.out.println("아이디가 틀리거나 회원이 아닙니다!!");
}
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
</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>
<div align = "center">
<h2>입력 폼(Ex01.jsp) 페이지에서 넘어온 데이터</h2>
<h3>
입력 받은 아이디 : <%=request.getParameter("id").trim() %> <br/>
입력 받은 비밀번호 : <%=request.getParameter("pwd").trim() %> <br/>
</h3>
<hr>
<h2>세션으로 넘어온 데이터</h2>
<h3>
세션으로 받은 이름 : <%=session.getAttribute("Name") %> <br/>
세션으로 받은 연락처 : <%=session.getAttribute("Phone") %> <br/>
</h3>
<hr>
<a href = "Ex01_03.jsp">다음으로</a>
</div>
</body>
</html>
Ex01_03.jsp 생성
Ex01_04.jsp 생성
사실상 Ex01_02 페이지이나 url 상에서는 Ex01_01로 보임
