Cookie&Session

[Session] 로그인 & 로그인 실패

퓨어맨 2022. 5. 16. 14:08
<%@ 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>
	<h1>로그인</h1>
	<%String id = (String)session.getAttribute("id");%>
	<%if(id != null){ %>
		<h1><%=id %></h1>
		<p>로그인 중입니다.</p>
		<a href="ex10_logout">로그아웃</a>
	<%} else{ %>
	<form action="ex10_login.jsp" method="post">
		ID : <input type="text", name = "id"> <br>
		PW : <input type="password", name = "pw"> <br>
		<input type="submit", value="로그인">
	</form>
	<%} %>
</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>
	<%
		// 1. 파라미터 수집
		String id = request.getParameter("id");
		String pw = request.getParameter("pw");
		
		// 2. id = smhrd? 그리고 pw = 12345?
		String nextPage = "";
		if(id.equals("smhrd") && pw.equals("12345")){
			// 로그인 성공
			// HttpSession session = request.getSession();
			
			session.setAttribute("id", id+"님");
			nextPage = "ex10_main.jsp";
		} else{
			// 로그인 실패
			nextPage = "ex10_loginF.jsp";
		}
				
		// 3. 결과에 따라 main or loginF로 이동
		response.sendRedirect(nextPage);
	%>

</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>
	<h1>로그인 실패</h1>
	<p>아이디나 비밀번호를 확인해주세요</p>
	<a href="ex10_main.jsp">로그인페이지로</a>
</body>
</html>

로그인 실패화면

 

 

'Cookie&Session' 카테고리의 다른 글

[Session] Scope(page,request,session,application)  (0) 2022.05.17
[Session] 로그아웃  (0) 2022.05.16
[Session] 세션 전체 삭제  (0) 2022.05.16
[Session] 세션 삭제  (0) 2022.05.16
[Session] 세션 수정  (0) 2022.05.16