2024-12-12









<%@ 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">
<hr width="30%" color="red">
<h2>세션 관련 내용</h2>
<hr width="30%" color="red">
<br> <br>
<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>
<%@ 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-1111");
// 이동할 페이지를 지정하는 메서드
RequestDispatcher rd = request.getRequestDispatcher("Ex01_02.jsp");
// 실제적으로 페이지 이동.
rd.forward(request, response);
}
} else {
// 아이디가 DB 테이블에 없거나 아이디가 잘못 일력된 경우
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 width="30%" color="gray">
<h2>세션으로 받은 데이터</h2>
<h3>
세션으로 받은 이름 : <%= session.getAttribute("Name") %> <br>
세션으로 받은 연락처 : <%= session.getAttribute("Phone") %> <br>
</h3>
<hr width="30%" color="gray">
<a href="Ex01_03.jsp">다음으로</a>
</div>
</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 width="30%" color="gray">
<h2>세션으로 받은 데이터</h2>
<h3>
세션으로 받은 이름 : <%= session.getAttribute("Name") %> <br>
세션으로 받은 연락처 : <%= session.getAttribute("Phone") %> <br>
</h3>
<hr width="30%" color="gray">
<a href="Ex01_04.jsp">다음으로</a>
</div>
</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 width="30%" color="gray">
<h2>세션으로 받은 데이터</h2>
<h3>
세션으로 받은 이름 : <%= session.getAttribute("Name") %> <br>
세션으로 받은 연락처 : <%= session.getAttribute("Phone") %> <br>
</h3>
<hr width="30%" color="gray">
<a href="Ex01_04.jsp">다음으로</a>
</div>
</body>
</html>'JSP > 기초 내용 정리' 카테고리의 다른 글
| JSP(Example)_EMP (0) | 2024.12.17 |
|---|---|
| JSP(Example)_Member (1) | 2024.12.13 |
| JSP(Session)_00 (0) | 2024.12.12 |
| JSP(JSP)_09 (0) | 2024.12.12 |
| JSP(JSP)_06~8 (0) | 2024.12.12 |