19.05.07 세션 사용 로그인 (동영상 38강~39강)
Back-End/JSP 2019. 5. 7. 23:11728x90
반응형
-예제 및 출력 결과-
SessionMain.jsp (각페이지를 포함하는 메인파일)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 |
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<%
//Center 값을 변경해주기 위해서 request 객체를 이용하여 center값을 받아옴
String center = request.getParameter("center");
//처음 SessionMain.jsp를 실행하면 null값이 실행되기에 null처리를 해줌
if(center == null)
{
center = "Center.jsp";
}
%>
<center>
<table border="1" width="800">
<!--top -->
<tr height="150">
<td align="center" colspan="2"><jsp:include page="Top.jsp" />
</td>
</tr>
<!-- Left -->
<tr height="400">
<td align="center" width="200"><jsp:include page="Left.jsp" />
</td>
<!-- Center -->
<td align="center" width="200"><jsp:include page="<%=center %>" />
</td>
</tr>
<!-- Bottom -->
<tr height="100">
<td align="center" colspan="2"><jsp:include page="Bottom.jsp" />
</td>
</tr>
</table>
</center>
</body>
</html> |
cs |
Top.jsp (상단 파일)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64 |
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<%
//로그아웃 클릭시 파라미터를 통해서 로그아웃인지여부 파악
String logout = request.getParameter("logout");
if (logout != null) {
//id에 null값을 부여
session.setAttribute("id", null);
//세션 유지를 종료
session.setMaxInactiveInterval(0);
}
//세션을 통하여 id를 읽어들인다.
String id = (String) session.getAttribute("id");
//로그인이 되어 있지 않다면 session값이 null이 된다. 그래서 null처리를 해줘야한다.
if (id == null) {
id = "손님";
}
%>
<!-- Top -->
<center>
<table width="800">
<tr height="100">
<!-- 로고이미지 -->
<td colspan="2" align="center" width="200"><img alt=""
src="img/logo.jpg" width="200" height="200"> <!-- 그림파일 가져오는 코드 --></td>
<td colspan="5" align="center"><font size="10">낭만 캠핑</font></td>
</tr>
<tr height="50">
<td width="100" align="center">텐트</td>
<td width="100" align="center">의자</td>
<td width="100" align="center">식기류</td>
<td width="100" align="center">침낭</td>
<td width="100" align="center">테이블</td>
<td width="100" align="center">화롯대</td>
<td width="200" align="center">
<%
if (id.equals("손님")) //아이디가 손님과 같다면 (로그인이 안된상태니 로그인 해야됨)
{
%> <%=id%>님
<button
onclick="location.href='SessionMain.jsp?center=SessionLoginForm.jsp'">로그인</button>
<%
} else {
%> <%=id%>님
<button onclick="location.href='SessionMain.jsp?logout=1'">로그아웃</button>
<%
}
%>
</td>
</table>
</center>
</body>
</html> |
cs |
Left.jsp (좌측 파일)
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
31
32
33
34 |
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<table width="200">
<tr height="60">
<td width="200" align="center"><a
href="SessionMain.jsp?center=Snowpeak.jsp">스노우피크</a></td>
<!--스노피크파일이 넘어감 -->
</tr>
<tr height="60">
<td width="200" align="center"><a
href="SessionMain.jsp?center=Coleman.jsp">콜맨</a></td>
</tr>
<tr height="60">
<td width="200" align="center"><a
href="SessionMain.jsp?center=Jeep.jsp">지프</a></td>
</tr>
<tr height="60">
<td width="200" align="center"><a
href="SessionMain.jsp?center=Kovea.jsp">코베아</a></td>
</tr>
</table>
</body>
</html> |
cs |
Center.jsp (중앙파일)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 |
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<table width = "600">
<tr height = "400">
<td align = "center">
<img alt = "" src = "img/auto.png" width = "500" height = "350"> <!-- 그림파일 불러옴 -->
</td>
</tr>
</table>
</body>
</html> |
cs |
Bottom.jsp (하단파일)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 |
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<table width="800">
<tr height="100">
<td align="center">이용약관 이메일 무단수집거부 개인정보 취급 (처리)방침 윤리경영 보안신고
Contact Us 사업장 소개 사이트맵 웹접근성 도움말<br> 배드민턴단 COPYRIGHT@2015
SAMSUNG ELECTRO-MECHANICS, All rights reserver.
</td>
</tr>
</table>
</body>
</html> |
cs |
SessionLoginForm.jsp(세션로그인)
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 |
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<%
//Center 값을 변경해주기 위해서 request 객체를 이용하여 center값을 받아옴
String center = request.getParameter("center");
//처음 SessionMain.jsp를 실행하면 null값이 실행되기에 null처리를 해줌
if(center == null)
{
center = "Center.jsp";
}
%>
<center>
<table border="1" width="800">
<!--top -->
<tr height="150">
<td align="center" colspan="2"><jsp:include page="Top.jsp" />
</td>
</tr>
<!-- Left -->
<tr height="400">
<td align="center" width="200"><jsp:include page="Left.jsp" />
</td>
<!-- Center -->
<td align="center" width="200"><jsp:include page="<%=center %>" />
</td>
</tr>
<!-- Bottom -->
<tr height="100">
<td align="center" colspan="2"><jsp:include page="Bottom.jsp" />
</td>
</tr>
</table>
</center>
</body>
</html> |
cs |
SessionLoginProc.jsp(세션로그인 처리)
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
31
32
33 |
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<center>
<h2>세션 로그인 처리 1</h2>
<%
request.setCharacterEncoding("EUC-KR"); //한글 깨짐을 방지하기 위해 문자셋 설정
//사용자로부터 데이터를 읽어들인다.
String id = request.getParameter("id"); //id와 pass를 각각 변수에 저장
String pass = request.getParameter("pass");
//아이디와 패스워드를 저장
session.setAttribute("id", id);
session.setAttribute("pass", pass);
//세션의 유지시간 설정
session.setMaxInactiveInterval(60*2); //2분간 아이디를 유지함
response.sendRedirect("SessionMain.jsp");
%>
</center>
</body>
</html>
|
cs |
Snowpeak.jsp (좌측 항목 중 1)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 |
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<table width="600">
<tr height="400">
<td align="center"><img alt="" src="img/snow.png" width="500"
height="350"> <!-- 그림파일 불러옴 --></td>
</tr>
</table>
</body>
</html> |
cs |
Kovea.jsp(좌측 항목 중 1)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 |
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<table width="600">
<tr height="400">
<td align="center"><img alt="" src="img/kovea.png" width="500"
height="350"> <!-- 그림파일 불러옴 --></td>
</tr>
</table>
</body>
</html> |
cs |
Coleman.jsp(좌측 항목 중 1)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 |
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<table width="600">
<tr height="400">
<td align="center"><img alt="" src="img/Jeep.jpg" width="500"
height="350"> <!-- 그림파일 불러옴 --></td>
</tr>
</table>
</body>
</html> |
cs |
Jeep.jsp (좌측 항목 중 1)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 |
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<table width="600">
<tr height="400">
<td align="center"><img alt="" src="img/Jeep.jpg" width="500"
height="350"> <!-- 그림파일 불러옴 --></td>
</tr>
</table>
</body>
</html> |
cs |
728x90
반응형
'Back-End > JSP' 카테고리의 다른 글
19.05.09 JSP 게시판 - 전체 게시글 보기 구현 (~동영상 45강) (0) | 2019.05.09 |
---|---|
19.05.08 JSP 게시판 - 시스템 구조 및 게시판 만들기 (~동영상 43강) (0) | 2019.05.08 |
19.05.07 회원가입 및 로그인 페이지 만들기 (0) | 2019.05.07 |
19.05.06 파일 업로드 (0) | 2019.05.06 |
19.05.05 커넥션풀을 사용한 데이터베이스 연결 (동영상) (0) | 2019.05.05 |