JSP(Session)_01

2024. 12. 12. 18:18·JSP/기초 내용 정리

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
'JSP/기초 내용 정리' 카테고리의 다른 글
  • JSP(Example)_EMP
  • JSP(Example)_Member
  • JSP(Session)_00
  • JSP(JSP)_09
mw41817
mw41817
일생의 개발 기록 저장소
  • mw41817
    IT 개발 일지
    mw41817
    • Index (487)
      • HTML (36)
        • 기초 내용 정리 (36)
      • CSS (29)
        • 기초 내용 정리 (29)
      • JavaScript (60)
        • 기초 내용 정리 (60)
      • JQuery (38)
        • 기초 내용 정리 (38)
      • Java (232)
        • 기초 내용 정리 (232)
      • JSP (46)
        • 기초 내용 정리 (46)
      • Spring, Boot (31)
        • 기초 내용 정리 (31)
      • DB (5)
        • Oracle SQL (5)
      • Code WorkBook (6)
        • programmers (6)
        • Baekjoon (0)
      • 기타 (1)
        • 유용한 사이트 (3)
  • 전체
    오늘
    어제
  • 글쓰기 관리
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
    • 카테고리
    • 주인장 GitHub
  • 공지사항

  • 인기 글

  • 태그

    html #코딩 #프로그래밍 #기초
  • 최근 댓글

  • hELLO· Designed By정상우.v4.10.0
mw41817
JSP(Session)_01
상단으로

티스토리툴바