์ƒˆ์†Œ์‹

์ธ๊ธฐ ๊ฒ€์ƒ‰์–ด

๐ŸŒ WEB/๐Ÿ“ฐ HTML

HTML ๊ธฐ์ดˆ - ์ฟ ํ‚ค

  • -
๋ฐ˜์‘ํ˜•
์ฟ ํ‚ค

์›น ๋ธŒ๋ผ์šฐ์ €์—์„œ ์„œ๋ฒ„๋กœ ์–ด๋–ค ๋ฐ์ดํ„ฐ๋ฅผ ์š”์ฒญํ•˜๋ฉด,

์„œ๋ฒ„์ธก์—์„œ๋Š” ์•Œ๋งž์€ ๋กœ์ง์„ ์ˆ˜ํ–‰ํ•œ ํ›„ ๋ฐ์ดํ„ฐ๋ฅผ ์›น ๋ธŒ๋ผ์šฐ์ €์— ์‘๋‹ต

์„œ๋ฒ„๋Š” ์›น ๋ธŒ๋ผ์šฐ์ €์™€์˜ ๊ด€๊ณ„๋ฅผ ์ข…๋ฃŒ

์›น๋ธŒ๋ผ์šฐ์ €์— ์‘๋‹ต ํ›„ ๊ด€๊ณ„๋ฅผ ๋Š๋Š” ๊ฒƒ์€ http ํ”„๋กœํ† ์ฝœ์˜ ํŠน์ง•

์—ฐ๊ฒฐ์ด ๋Š๊ฒผ์„ ๋•Œ ์–ด๋–ค ์ •๋ณด๋ฅผ ์ง€์†์ ์œผ๋กœ ์œ ์ง€ํ•˜๊ธฐ ์œ„ํ•œ ์ˆ˜๋‹จ์œผ๋กœ ์ฟ ํ‚ค๋ผ๋Š” ๋ฐฉ์‹์„ ์‚ฌ์šฉ

์ฟ ํ‚ค๋Š” ์„œ๋ฒ„์—์„œ ์ƒ์„ฑ, ํด๋ผ์ด์–ธํŠธ ์ธก์— ํŠน์ • ์ •๋ณด๋ฅผ ์ €์žฅ

์„œ๋ฒ„์— ์š”์ฒญ ํ•  ๋•Œ ๋งˆ๋‹ค ์ฟ ํ‚ค์˜ ์†์„ฑ๊ฐ’์„ ์ฐธ์กฐ ๋˜๋Š” ๋ณ€๊ฒฝ ๊ฐ€๋Šฅ

 

์ฟ ํ‚ค ๊ด€๋ จ ๋ฉ”์†Œ๋“œ

setMaxAge() : ์ฟ ํ‚ค ์œ ํšจ๊ธฐ๊ฐ„์„ ์„ค์ • ํ•ฉ๋‹ˆ๋‹ค.

setpath() : ์ฟ ํ‚ค์‚ฌ์šฉ์˜ ์œ ํšจ ๋””๋ ‰ํ† ๋ฆฌ๋ฅผ ์„ค์ • ํ•ฉ๋‹ˆ๋‹ค.

setValue() : ์ฟ ํ‚ค์˜ ๊ฐ’์„ ์„ค์ • ํ•ฉ๋‹ˆ๋‹ค.

setVersion() : ์ฟ ํ‚ค ๋ฒ„์ „์„ ์„ค์ • ํ•ฉ๋‹ˆ๋‹ค.

getMaxAge() : ์ฟ ํ‚ค ์œ ํšจ๊ธฐ๊ฐ„ ์ •๋ณด๋ฅผ ์–ป์Šต๋‹ˆ๋‹ค.

getName() : ์ฟ ํ‚ค ์ด๋ฆ„์„ ์–ป์Šต๋‹ˆ๋‹ค.

getPath() : ์ฟ ํ‚ค์‚ฌ์šฉ์˜ ์œ ํšจ ๋””๋ ‰ํ† ๋ฆฌ ์ •๋ณด๋ฅผ ์–ป์Šต๋‹ˆ๋‹ค.

getValue() : ์ฟ ํ‚ค์˜ ๊ฐ’์„ ์–ป์Šต๋‹ˆ๋‹ค.

getVersion() : ์ฟ ํ‚ค ๋ฒ„์ „์„ ์–ป์Šต๋‹ˆ๋‹ค.

// login-form.jsp

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
	<h1>๋กœ๊ทธ์ธ ํŽ˜์ด์ง€</h1>
	<form action="login-ok.jsp" method="get">
		ID : <input type="text" class="id" name="id"><br>
		PW : <input type="password" id="pw" name="pw"><br>
		<input type="checkbox" name="id-check" value="ok"> ์•„์ด๋”” ์ €์žฅ
		<input type="submit" value="๋กœ๊ทธ์ธ">
	</form>

</body>
</html>
// login-ok.jsp
// ์ฒ˜์Œ ์ฟ ํ‚ค ์ƒ์„ฑ

<%@page import="java.net.URLEncoder"%>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
	<h1> ์ฟ ํ‚ค ์ƒ์„ฑ ์™„๋ฃŒ </h1>
	<%
		Cookie info = new Cookie("test",URLEncoder.encode("hello cookie","utf-8"));
		
		info.setMaxAge(60*60);
		info.setPath("/");
		
		response.addCookie(info);
	%>

</body>
</html>

 

 

// ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์–ด๋– ํ•œ ์š”์ฒญ์„ ํ•˜๊ณ , ์„œ๋ฒ„์—์„œ ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ๋ฐ›์€ ์ฟ ํ‚ค๋ฅผ ์ถ”์ถœ 
// login-form.jsp

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
	<%
		Cookie[] cookie = request.getCookies();
		String id ="";		
		
		for(int i=0 ; i<cookie.length ; i++){
			if(cookie[i].getName().equals("test")){
				id = cookie[i].getValue();
			}
		}
	%>
	<h1>๋กœ๊ทธ์ธ ํŽ˜์ด์ง€</h1>
	<form action="login-ok.jsp" method="get">
		ID : <input type="text" class="id" name="id" value="<%=id%>"><br>
		PW : <input type="password" id="pw" name="pw"><br>
		<input type="checkbox" name="id-check" value="ok"> ์•„์ด๋”” ์ €์žฅ
		<input type="submit" value="๋กœ๊ทธ์ธ">
	</form>

</body>
</html>
// login-ok.jsp

<%@page import="java.net.URLEncoder"%>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
	<h1> ์ฟ ํ‚ค ์ƒ์„ฑ ์™„๋ฃŒ </h1>
	<%
		String[] idCheck = request.getParameterValues("id-check");
		String id = request.getParameter("id");
		
		if(idCheck !=null && idCheck[0].equals("ok")){
			
			Cookie info = new Cookie("test",URLEncoder.encode(id,"utf-8"));
			
			info.setMaxAge(60*60);
			info.setPath("/");
			
			response.addCookie(info);
			
		}else{
			// ์ฟ ํ‚ค ์‚ญ์ œ
			Cookie[] cookie = request.getCookies();
			for(int i=0; i<cookie.length; i++){
				
				if(cookie[i].getName().equals("test")){
					cookie[i].setMaxAge(0);
					cookie[i].setPath("/");
					response.addCookie(cookie[i]);
					
				}
			}
			
		}

	%>

</body>
</html>

์•„์ด๋”” ์ €์žฅ์„ ๋ˆŒ๋ €์„ ๋•Œ ์ฟ ํ‚ค๋กœ ์ธํ•ด ์ƒˆ๋กœ๊ณ ์นจ์„ ํ•ด๋„ ์•„์ด๋””๊ฐ€ ์‚ฌ๋ผ์ง€์ง€ ์•Š์Œ
์•„์ด๋”” ์ €์žฅ์„ ์ฒดํฌ ํ•ด์ œ ํ–ˆ์„ ๋•Œ ์ฟ ํ‚ค ์‚ญ์ œ๋ผ์„œ ์•„์ด๋””๊ฐ€ ์‚ฌ๋ผ์ง

๋ฐ˜์‘ํ˜•
Contents

ํฌ์ŠคํŒ… ์ฃผ์†Œ๋ฅผ ๋ณต์‚ฌํ–ˆ์Šต๋‹ˆ๋‹ค

์ด ๊ธ€์ด ๋„์›€์ด ๋˜์—ˆ๋‹ค๋ฉด ๊ณต๊ฐ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.