티스토리 뷰

<%@ 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>
	<%
		String id = (String) session.getAttribute("id");
		if (id == null) {
	%>

	<form action="exam3_login_check.jsp" method="post">
		<input type="text" name="id" placeholder="아이디"><br> <input
			type="password" name="pw" placeholder="비밀번호"><br> <input
			type="submit" value="로그인"><br>
	</form>
		<%
			}else{	%>
	
		<%=id%>님 로그인 되셨습니다. 
		<a href="exam3_loginout.jsp">로그아웃</a>
		<%
			}
		%>

</body>
</html>

exam3_login.jsp페이지

 

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%
	request.setCharacterEncoding("utf-8");
String id = request.getParameter("id");
String pw = request.getParameter("pw");

if (id.equals("test") && pw.equals("1234")) {

	session.setAttribute("id", "test");
	session.setAttribute("check", "remember");
%>
<script>
	alert('로그인 성공');
	location.href = 'exam3_login.jsp';
</script>
<%
	} else {
%>
<script>
	alert('로그인 실패');
	location.href = "exam2_login.jsp";
</script>
<%
	}
%>

exam3_login_check.jsp페이지

 

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
 	session.invalidate();
%>
<script>
	alert('로그아웃');
	location.href="exam3_login.jsp";
</script>

exam3_loginout.jsp페이지

 


[결과 페이지]

로그인전 화면
로그인 후 화면

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/06   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
글 보관함