JDBC(Oracle)

[JDBC] Auth(์ธ์ฆ ๋ฐ ํ—ˆ๊ฐ€) ๋กœ๊ทธ์ธ ๊ตฌํ˜„

developer of the night sky 2023. 10. 23. 14:10

๐Ÿ”ป์ธ์ฆ๊ณผ ํ—ˆ๊ฐ€

์ธ์ฆ, Authentication

  • ํ˜„์žฌ ์ ‘์†์ž๊ฐ€ ํ•ด๋‹น ์‚ฌ์ดํŠธ์˜ ๊ตฌ์„ฑ์›์ธ์ง€ ํ™•์ธํ•˜๋Š” ์ž‘์—…
  • ๋กœ๊ทธ์ธ(Sign in), ๋กœ๊ทธ์•„์›ƒ(Sign out)
  • ํ•ด๋‹น ์ ‘์†์ž๊ฐ€ ๊ตฌ์„ฑ์›์ธ์ง€ ์•„์ด๋””์™€ ์•”ํ˜ธ๋กœ ํ™•์ธํ•˜๋Š” ์ž‘์—…์„ ํ†ต๊ณผํ•˜๋ฉด ์ธ์ฆ ํ‹ฐ์ผ“์„ ๋ฐœ๊ธ‰ํ•œ๋‹ค.
  • ์ธ์ฆ ํ‹ฐ์ผ“์œผ๋กœ ์‚ฌ์ดํŠธ ๋‚ด์—์„œ ์ž์œ ๋กญ๊ฒŒ ์ด๋™์ด ๊ฐ€๋Šฅํ•˜๊ณ  ์ธ์ฆ ๋ฐ›์€ ์‚ฌ๋žŒ์ด๋ผ๋Š” ๊ฒƒ์„ ์ฆ๋ช… ๊ฐ€๋Šฅํ•˜๋‹ค.

ํ—ˆ๊ฐ€, Authorization

  • ํŠน์ • ํ–‰๋™์„ ํ•  ๋•Œ ๊ถŒํ•œ์ด ์žˆ๋Š”์ง€ ํ™•์ธํ•˜๋Š” ์ž‘์—…

 

์›น ๋ณด์•ˆ์€ ์ธ์ฆ๊ณผ ํ—ˆ๊ฐ€๋ฅผ ํ•ฉ์ณ์„œ ๊ด€๋ฆฌํ•œ๋‹ค.

์ธ์ฆ์„ ํ™•์ธํ•˜๋Š” ๋ฐฉ๋ฒ•์—๋Š” ์„ธ์…˜ ๊ธฐ๋ฐ˜ ์ธ์ฆ ๋ฐฉ๋ฒ•๊ณผ ์ฟ ํ‚ค ๊ธฐ๋ฐ˜ ์ธ์ฆ ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค.


๐Ÿ”ป์ธ์ฆ ์—…๋ฌด ๊ตฌํ˜„(๋กœ๊ทธ์ธ ๋ฐ ๊ถŒํ•œ ์žˆ๋Š” ํŽ˜์ด์ง€ ๋งŒ๋“ค๊ธฐ)

  • ์„ธ์…˜ ๊ธฐ๋ฐ˜ ์ธ์ฆ ๋ฐฉ๋ฒ•์œผ๋กœ ๊ตฌํ˜„ํ•œ๋‹ค.
  • ํ”„๋กœ์ ํŠธ ๋ช… : AuthTest
ํด๋” ๊ฒฝ๋กœ ํŒŒ์ผ๋ช… ํŒŒ์ผ ์—ญํ• 
AuthTest  script.sql  sql ๊ตฌ๋ฌธ์„ ์ž‘์„ฑํ•˜๋Š” ํŒŒ์ผ
WEB-INF > lib  ojdbc6.jar  
webapp  index.jsp  ์‹œ์ž‘ ํŽ˜์ด์ง€
webapp > auth login .jsp ๋กœ๊ทธ์ธ ํผ ํŽ˜์ด์ง€
webapp > auth loginok.jsp  ๋กœ๊ทธ์ธ ์ฒ˜๋ฆฌ ํŽ˜์ด์ง€(+ ์ธ์ฆ ์ž‘์—…)
webapp > auth logoutok.jps ๋กœ๊ทธ์•„์›ƒ ์ฒ˜๋ฆฌ ํŽ˜์ด์ง€
webapp > member member.jsp ํšŒ์› ์ „์šฉ ํŽ˜์ด์ง€(+ํ—ˆ๊ฐ€ ์ž‘์—…)
webapp  > admin admin.jsp ๊ด€๋ฆฌ์ž ์ „์šฉ ํŽ˜์ด์ง€(+ํ—ˆ๊ฐ€ ์ž‘์—…)
com.test.auth DBUtil.java DBUtil.java

 

 

 


sql ๊ตฌ๋ฌธ ์ž‘์„ฑ

sql๊ตฌ๋ฌธ์„ sql ํˆด๋กœ ๋ฏธ๋ฆฌ ์ž‘์„ฑํ•˜๋ฉด ๋‚˜์ค‘์— JSP์—์„œ sql๊ตฌ๋ฌธ ์กฐ์ž‘ํ•˜๊ธฐ ํŽธํ•˜๋‹ค.

 script.sql

-- AuthTest > script.sql

select * from tblUser;

create table tblUser (
    id varchar2(30) primary key,    -- ์•„์ด๋””(PK)
    pw varchar2(30) not null,       -- ์•”ํ˜ธ
    name varchar2(30) not null,      -- ์ด๋ฆ„
    lv number(1) not null           -- ๋“ฑ๊ธ‰(1-์ผ๋ฐ˜, 2-๊ด€๋ฆฌ์ž)
);

insert into tblUser values ('hong', '1111', 'ํ™๊ธธ๋™', 1);
insert into tblUser values ('test', '1111', 'ํ…Œ์ŠคํŠธ', 1);
insert into tblUser values ('admin', '1111', '๊ด€๋ฆฌ์ž', 2);

select * from tblUser where id = 'hong' and pw = '1111';

commit;

sql๊ตฌ๋ฌธ์„ sql ํˆด๋กœ ๋ฏธ๋ฆฌ ์ž‘์„ฑํ•˜๋ฉด ๋‚˜์ค‘์— JSP์—์„œ sql๊ตฌ๋ฌธ ์กฐ์ž‘ํ•˜๊ธฐ ํŽธํ•˜๋‹ค.

 

 

์‹œ์ž‘ํŽ˜์ด์ง€

index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>์ธ์ฆ/ํ—ˆ๊ฐ€</title>
<link rel="stylesheet" href="http://pinnpublic.dothome.co.kr/cdn/example-min.css">
</head>
<body>

	<h1>์ธ์ฆ/ํ—ˆ๊ฐ€</h1>
	
	<% if(session.getAttribute("auth") == null) {%>
	<fieldset>
		<input type="button" value="๋กœ๊ทธ์ธ" onclick = "location.href='auth/login.jsp';">
	</fieldset>
	<% } else { %>
	<fieldset>
		<input type="button" value="๋กœ๊ทธ์•„์›ƒ" onclick = "location.href='auth/logoutok.jsp';">
		<div class="message">
			<div>์•„์ด๋””: <%= session.getAttribute("auth") %> </div>
			<div>์ด๋ฆ„: <%= session.getAttribute("name") %> </div>
			<div>๋“ฑ๊ธ‰: <%=session.getAttribute("lv").toString().equals("1")?"์ผ๋ฐ˜ํšŒ์›":"๊ด€๋ฆฌ์ž" %></div>
		</div>
	</fieldset>
	<% } %>
	
	<hr>
	
	<!-- ํšŒ์› ์ „์šฉ ํŽ˜์ด์ง€  -->
	<!-- ๋…ธ์ถœ ์œ ๋ฌด ๋ฐฉ๋ฒ• 1 : ๋””์Šคํ”Œ๋ ˆ์ด ๋…ธ์ถœ ์œ ๋ฌด๋ฅผ -->
	<% if(session.getAttribute("auth") != null) { %>
	<div><a href="member/member.jsp">ํšŒ์› ํŽ˜์ด์ง€</a></div>
	<% } %>
	 
	<%-- 
	<!-- ๋…ธ์ถœ ์œ ๋ฌด ๋ฐฉ๋ฒ• 2 : ๊ธฐ๋Šฅ ์ฐจ์ด๋ฅผ ๋‘”๋‹ค.-->
	<% if(session.getAttribute("auth") != null) { %>
	<div><a href="member/member.jsp">ํšŒ์› ํŽ˜์ด์ง€</a></div>
	<% } else { %>
	<!-- ํšŒ์›์ด ์•„๋‹Œ ์‚ฌ๋žŒ -->
	<!-- #!๋กœ ๊ณต์ˆ˜ํ‘œ๋ฅผ ๋งŒ๋“ ๋‹ค -->
	<a href="#!" onclick = "alert('๋กœ๊ทธ์ธํ•œ ํšŒ์›๋งŒ ์ ‘๊ทผ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.');">ํšŒ์› ํŽ˜์ด์ง€</a>
	<%} %>
	--%>
	
	<!-- ๊ด€๋ฆฌ์ž ์ „์šฉ ํŽ˜์ด์ง€ -->
	<% if (session.getAttribute("auth") != null && session.getAttribute("lv").toString().equals("2")) { %>
	<div><a href="admin/admin.jsp">๊ด€๋ฆฌ์ž ํŽ˜์ด์ง€</a></div>
	<% } %>
	

	<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
	<script src="http://pinnpublic.dothome.co.kr/cdn/example-min.js"></script>
</body>
</html>

์„ธ์…˜ ๊ฐ์ฒด์˜ auth ์†์„ฑ์„ ํ™œ์šฉํ•˜์—ฌ ์‚ฌ์šฉ์ž์˜ ๋กœ๊ทธ์ธ ์ƒํƒœ๋ฅผ ํŒŒ์•…ํ•  ์ˆ˜ ์žˆ๋‹ค.

๋งŒ์•ฝ auth ์†์„ฑ์ด null์ด๋ผ๋ฉด, ์‚ฌ์šฉ์ž๋Š” ๋กœ๊ทธ์ธํ•˜์ง€ ์•Š์•˜๋‹ค๋Š” ๊ฒƒ์„ ์˜๋ฏธํ•˜๋ฉฐ ์ด๋•Œ ๋กœ๊ทธ์ธ ๋ฒ„ํŠผ์ด ํ™”๋ฉด์— ์ถœ๋ ฅ๋œ๋‹ค.
๋ฐ˜๋ฉด, auth ์†์„ฑ์ด null์ด ์•„๋‹Œ ๊ฒฝ์šฐ, ์‚ฌ์šฉ์ž๋Š” ๋กœ๊ทธ์ธ์„ ํ•œ ์ƒํƒœ์ด๋‹ค. ์ด๋•Œ๋Š” ๋กœ๊ทธ์•„์›ƒ ๋ฒ„ํŠผ๊ณผ ๋กœ๊ทธ์ธํ•œ ์‚ฌ์šฉ์ž์˜ ์ •๋ณด๊ฐ€ ํ™”๋ฉด์— ํ‘œ์‹œ๋œ๋‹ค.

๋˜ํ•œ, ํšŒ์› ๋ฐ ๊ด€๋ฆฌ์ž ํŽ˜์ด์ง€์— ์ ‘๊ทผ ๊ถŒํ•œ์„ ๋ถ€์—ฌํ•˜๊ธฐ ์œ„ํ•ด auth ์†์„ฑ์„ ํ™œ์šฉํ•œ๋‹ค. ์‚ฌ์šฉ์ž๊ฐ€ ๋กœ๊ทธ์ธํ•œ ๊ฒฝ์šฐ์—๋งŒ ํ•ด๋‹น ํŽ˜์ด์ง€๋กœ์˜ ์ ‘๊ทผ์ด ํ—ˆ์šฉ๋˜๋ฉฐ, ๊ทธ๋ ‡์ง€ ์•Š์€ ๊ฒฝ์šฐ์—๋Š” ์ ‘๊ทผํ•  ์ˆ˜ ์—†๋‹ค.
์ด๋Ÿฌํ•œ ์ ‘๊ทผ ์ œ์–ด๋ฅผ ๊ตฌํ˜„ํ•˜๋Š” ๋ฐฉ๋ฒ•์—๋Š” ๋‘ ๊ฐ€์ง€ ๋ฐฉ์‹์ด ์žˆ๋‹ค.

์ฒซ ๋ฒˆ์งธ ๋ฐฉ๋ฒ•์€ ๋กœ๊ทธ์ธํ•œ ๊ฒฝ์šฐ์—๋งŒ ํšŒ์› ํŽ˜์ด์ง€๋กœ์˜ ์ ‘๊ทผ์„ ํ—ˆ์šฉํ•˜๋Š” ๋ฒ„ํŠผ์„ ์ œ๊ณตํ•˜๋Š” ๊ฒƒ์ด๋‹ค. ๋‘ ๋ฒˆ์งธ ๋ฐฉ๋ฒ•์€ ๋กœ๊ทธ์ธ ์ „ํ›„ ๋ฒ„ํŠผ์ด ๋ณด์—ฌ์ง€์ง€๋งŒ ๋กœ๊ทธ์ธ ์ „ ๋ฒ„ํŠผ์„ ๋ˆŒ๋ €์„ ๋•Œ, ์ด๋™ํ•˜์ง€์•Š๊ณ  ์•ˆ๋‚ด๋ฉ”์‹œ์ง€๋งŒ ๋„์–ด์ฃผ๋Š” ์ด๋ฅธ๋ฐ” ๊ณต์ˆ˜ํ‘œ๋ฅผ ๋„์šฐ๋Š” ๊ฒƒ์ด๋‹ค. aํƒœ๊ทธ ๋งํฌ์— "#!"๋ฅผ ๋„ฃ์œผ๋ฉด ๊ณต์ˆ˜ํ‘œ๊ฐ€ ๋œ๋‹ค.

 

 

๋กœ๊ทธ์ธ ํผ ํŽ˜์ด์ง€

login.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>๋กœ๊ทธ์ธ</title>
<link rel="stylesheet" href="http://pinnpublic.dothome.co.kr/cdn/example-min.css">
</head>
<body>

	<h1>๋กœ๊ทธ์ธ</h1>

	<form method="POST" action="loginok.jsp">
	<table class="vertical">
		<tr>
			<th>์•„์ด๋””</th>
			<td><input type="text" name="id" required></td>
		</tr>
		<tr>
			<th>์•”ํ˜ธ</th>
			<td><input type="password" name="pw" required></td>
		</tr>
	</table>
	<div>
		<input type="submit" value="๋กœ๊ทธ์ธ">
	</div>
	</form>

	<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
	<script src="http://pinnpublic.dothome.co.kr/cdn/example-min.js"></script>
	
</body>
</html>

 

 

๋กœ๊ทธ์ธ ์ฒ˜๋ฆฌ ํŽ˜์ด์ง€

loginok.jsp

<%@page import="com.test.auth.DBUtil"%>
<%@page import="java.sql.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	//1.
	String id = request.getParameter("id");
	String pw = request.getParameter("pw");
	
	//2.
	Connection conn = null;
	PreparedStatement stat = null;
	ResultSet rs = null;
	
	try {
		
		conn = DBUtil.open();
		
		String sql = "select * from tblUser where id = ? and pw = ?";
		
		stat = conn.prepareStatement(sql);
		stat.setString(1, id);
		stat.setString(2, pw);
		
		rs = stat.executeQuery();
		
		if (rs.next()) {
			//ํ•ด๋‹น ๊ตฌ๋ฌธ์—์„œ ๋กœ๊ทธ์ธ ์ฒ˜๋ฆฌ๋ฅผ ๋๋‚ธ๋‹ค. ๋‹ค๋ฅธ ๊ณณ์—์„œ ์ž‘์„ฑํ•˜์ง€ ์•Š๋Š”๋‹ค.
			
			session.setAttribute("auth", id);	// ์ธ์ฆ ํ‹ฐ์ผ“ ์—ญํ• 
			session.setAttribute("name", rs.getString("name"));
			session.setAttribute("lv", rs.getString("lv"));
			response.sendRedirect("../index.jsp");
			
		} else {
			System.out.println("๋กœ๊ทธ์ธ ์‹คํŒจ");
			response.sendRedirect("login.jsp");
		}
		
		rs.close();
		stat.close();
		conn.close();
	} catch (Exception e) {
		e.printStackTrace();
	}
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="http://pinnpublic.dothome.co.kr/cdn/example-min.css">
</head>
<body>
	<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
	<script src="http://pinnpublic.dothome.co.kr/cdn/example-min.js"></script>
</body>
</html>

๋กœ๊ทธ์ธ ์ฒ˜๋ฆฌํŽ˜์ด์ง€์—์„œ๋Š” ์ด 4๊ฐ€์ง€์˜ ์—…๋ฌด๋ฅผ ์ฒ˜๋ฆฌํ•œ๋‹ค.

1. login.jsp์—์„œ ๋„˜์–ด์˜จ id,pw ๋ฐ์ดํ„ฐ๋ฅผ ์ˆ˜์‹ ํ•œ๋‹ค.

2. DB์— ํ•ด๋‹น id,pw ๊ฐ€ ์žˆ๋Š” ํšŒ์›์„ ์กฐํšŒํ•œ๋‹ค.(select)

3. ์กด์žฌํ•˜๋ฉด ์ธ์ฆ ํ‹ฐ์ผ“์„ ๋ฐœ๊ธ‰ํ•˜๊ณ  ์กด์žฌํ•˜์ง€์•Š์œผ๋ฉด ์•„๋ฌด์ผ์ด ๋ฐœ์ƒํ•˜์ง€ ์•Š๋Š”๋‹ค.

4. ์‚ฌ์šฉ์ž์—๊ฒŒ ํ”ผ๋“œ๋ฐฑ์„ ํ•œ๋‹ค.

 

session.setAttribute("auth", id);

3๋ฒˆ์˜ ์ธ์ฆ ํ‹ฐ์ผ“ ์—ญํ• ์€ session์— auth ์†์„ฑ์„ ์ง€์ •ํ•˜๋Š” ๊ฒƒ์ด๋‹ค.

DB๊ฒฐ๊ณผ ๋ฐ˜ํ™˜ ํ›„ ํšŒ์›์ด ์กด์žฌํ•œ๋‹ค๋ฉด session์— auth ์†์„ฑ์„ id๋กœ ์ €์žฅํ•˜์—ฌ ์ธ์ฆ ํ‹ฐ์ผ“์„ ๋ฐœ๊ธ‰ํ•œ๋‹ค. ๋กœ๊ทธ์ธ์„ ์„ฑ๊ณตํ–ˆ๋‹ค๋Š” ํ‘œ์‹œ๋กœ ํšŒ์›์ด ๋‹ค๋ฅธ ํŽ˜์ด์ง€๋ฅผ ์ ‘์†ํ–ˆ์„ ๋•Œ, session์˜ auth ์†์„ฑ์„ ํ™•์ธํ•˜๋ฉด ๊ทธ ํŽ˜์ด์ง€์— ๊ถŒํ•œ์ด ์žˆ๋‹ค๋Š” ๊ฒƒ์„ ์ฆ๋ช…ํ•˜๋Š” ์ธ์ฆ ํ‹ฐ์ผ“์ด ๋˜๋Š” ๊ฒƒ์ด๋‹ค.

๋‹จ, ์„ธ์…˜์€ ์„œ๋ฒ„ ๋ฉ”๋ชจ๋ฆฌ๋ฅผ ์ฐจ์ง€ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ํ•„์š”ํ•œ ์ •๋ณด๋งŒ session ๊ฐ์ฒด์— ๋„ฃ์–ด์•ผํ•œ๋‹ค.

 

 

๋กœ๊ทธ์•„์›ƒ ์ฒ˜๋ฆฌ ํŽ˜์ด์ง€

logout.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	session.removeAttribute("auth");	//๋กœ๊ทธ์•„์›ƒ
	
	response.sendRedirect("../index.jsp");
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="http://pinnpublic.dothome.co.kr/cdn/example-min.css">
</head>
<body>
	<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
	<script src="http://pinnpublic.dothome.co.kr/cdn/example-min.js"></script>
</body>
</html>

๋กœ๊ทธ์•„์›ƒ ์ฒ˜๋ฆฌํŽ˜์ด์ง€์—์„œ๋Š” 2๊ฐ€์ง€ ์—…๋ฌด๋ฅผ ์ฒ˜๋ฆฌํ•œ๋‹ค.

1. ๋กœ๊ทธ์•„์›ƒ ์ฒ˜๋ฆฌ

2. ํ”ผ๋“œ๋ฐฑ

session.removeAttribute("auth");

session์˜ auth ์†์„ฑ์„ ์ง€์šฐ๋ฉด ๋กœ๊ทธ์•„์›ƒ ์ฒ˜๋ฆฌ๊ฐ€ ๋˜๋Š” ๊ฒƒ์ด๋‹ค.

๋กœ๊ทธ์ธ์€ ์ธ์ฆ ํ‹ฐ์ผ“์„ ์†Œ์œ ํ•˜๊ณ  ์žˆ๋Š” ์ƒํƒœ์ด๊ณ  ๋กœ๊ทธ์•„์›ƒ์€ ์ธ์ฆ ํ‹ฐ์ผ“์„ ์†Œ์œ ํ•˜๊ธฐ ์ „์ธ ์ƒํƒœ์ด๋ฏ€๋กœ ์ธ์ฆ ์ „ ์ƒํƒœ๋กœ ๋˜๋Œ๋ฆฐ๋‹ค.

 

 

ํšŒ์› ํŽ˜์ด์ง€

member.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	if (session.getAttribute("auth") == null) {
		//response.sendRedirect("../index.jsp");	// ๋ฐ”๋กœ ๋‚ด์ซ“๋Š”๊ฑด ๋ถˆ์นœ์ ˆํ•ด๋ณด์ž„
		
		out.println("<html>");
		out.println("<head>");
		out.println("<meta charset='UTF-8'>");
		out.println("</head>");
		out.println("<body>");
		out.println("<script>");
		out.println("alert('ํšŒ์›๋งŒ ์ ‘๊ทผ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.');");
		out.println("location.href='../index.jsp';");
		out.println("</script>");
		out.println("</body>");
		out.println("</html>");
		out.close();	// ์•„๋ž˜์˜ ์ฝ”๋“œ๋ฅผ ์ง„ํ–‰ํ•˜์ง€ ์•Š๊ณ  ์—ฌ๊ธฐ์„œ ์ค‘๋‹จํ•œ๋‹ค.
	}
%>    
    
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="http://pinnpublic.dothome.co.kr/cdn/example-min.css">
</head>
<body>
	<h1>ํšŒ์› ์ „์šฉ ํŽ˜์ด์ง€</h1>

	<p>์ด ํŽ˜์ด์ง€๋Š” ํšŒ์›๋งŒ ์ ‘๊ทผ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.</p>
	<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
	<script src="http://pinnpublic.dothome.co.kr/cdn/example-min.js"></script>
</body>
</html>

์ธ์ฆ๋ฐ›์ง€ ๋ชปํ•œ ์‚ฌ์šฉ์ž๊ฐ€ ์ง์ ‘ ์ ‘๊ทผํ•˜๋ฉด ํŽ˜์ด์ง€๊ฐ€ ๋ณด์ด์ง€์•Š๊ฒŒ ํ•ด์•ผํ•œ๋‹ค.

๋ณด์ด์ง€์•Š๊ฒŒ ํ•˜๋Š”๊ฑด ์—ฌ๋Ÿฌ ๋ฐฉ๋ฒ•์ด ์žˆ์ง€๋งŒ ๋ฐ”๋กœ ์‹œ์ž‘ํŽ˜์ด์ง€๋กœ ์ด๋™์‹œํ‚ค๋Š”๊ฑด ๋ถˆ์นœ์ ˆํ•ด๋ณด์ด๊ธฐ๋•Œ๋ฌธ์— ์•ˆ๋‚ด๋ฉ”์‹œ์ง€๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.

์•„๋ž˜ body์˜์—ญ์€ ํšŒ์›๋งŒ ๋ณด๋Š” ํŽ˜์ด์ง€์ด๊ธฐ์— ์ธ์ฆ ๊ฒ€์ฆ์„ ํ•  ๋•Œ๋Š” ๋ณดํ†ต ์Šคํฌ๋ฆฝํŠธ๋ฆฟ ์˜์—ญ์•ˆ์—์„œ ์ž‘์„ฑํ•œ๋‹ค.

 

 

๊ด€๋ฆฌ์ž ํŽ˜์ด์ง€

admin.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	if (session.getAttribute("auth") == null || session.getAttribute("lv").toString().equals("1")) {
		
		out.println("<html>");
		out.println("<head>");
		out.println("<meta charset='UTF-8'>");
		out.println("</head>");
		out.println("<body>");
		out.println("<script>");
		out.println("alert('๊ด€๋ฆฌ์ž๋งŒ ์ ‘๊ทผ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.');");
		out.println("location.href='../index.jsp';");
		out.println("</script>");
		out.println("</body>");
		out.println("</html>");
		out.close();	// ์•„๋ž˜์˜ ์ฝ”๋“œ๋ฅผ ์ง„ํ–‰ํ•˜์ง€ ์•Š๊ณ  ์—ฌ๊ธฐ์„œ ์ค‘๋‹จํ•œ๋‹ค.
	}
	
%>    
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="http://pinnpublic.dothome.co.kr/cdn/example-min.css">
<style>

</style>
</head>
<body>
	<h1>๊ด€๋ฆฌ์ž ํŽ˜์ด์ง€</h1>

	<p>์ด ํŽ˜์ด์ง€๋Š” ๊ด€๋ฆฌ์ž๋งŒ ์ ‘๊ทผ ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค.</p>
	<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
	<script src="http://pinnpublic.dothome.co.kr/cdn/example-min.js"></script>
</body>
</html>

๊ด€๋ฆฌ์ž ํŽ˜์ด์ง€๋„ ํšŒ์› ํŽ˜์ด์ง€์™€ ๊ฐ™์ด ์ „์šฉํŽ˜์ด์ง€๋ฅผ ์ง์ ‘ ์ ‘๊ทผํ–ˆ์„ ๋•Œ ์ธ์ฆ ๋‹จ๊ณ„๋ฅผ ๊ฑฐ์ณ ํŽ˜์ด์ง€๋ฅผ ์ถœ๋ ฅํ•œ๋‹ค.