CookieLogin.jsp
<%@ 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>CookieLogin</title>
</head>
<body>
<form action="CookieLoginProc.jsp">
<table>
<tr>
<td>id</td>
<td><input type="text" name="id"></td>
</tr>
<tr>
<td>pw</td>
<td><input type="text" name="pw"></td>
</tr>
<tr>
<td><input type="submit" value="Send"></td>
</tr>
</table>
</form>
</body>
</html>
CookieLogin1.jsp
<%@ 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></title>
</head>
<body>
<%
Cookie[] cookies = request.getCookies();
if(cookies!=null && cookies.length>0)
{
for(int i=0; i<cookies.length; i++)
{
if(cookies[i].getValue().equals("jiniusman"))
{
%>
id <%= cookies[i].getValue() %> log-in.<br>
<%
}
// else
%>
<!-- login failed. -->
<%
}
}
%>
</body>
</html>
CookieProc.jsp
<%@ 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>CookieLoginProc</title>
</head>
<body>
<%
String id_ = "jiniusman";
String pw_ = "blogspot";
String id = request.getParameter("id");
String pw = request.getParameter("pw");
if(id.equals(id_) && pw.equals(pw_))
response.addCookie(new Cookie("cookie_id", id));
response.sendRedirect("CookieLogin1.jsp");
%>
</body>
</html>
result)
댓글 없음:
댓글 쓰기