실습문제7-1.pdf
forward.jsp
<%@ 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>
<h4>구구단 출력하기</h4>
<jsp:forward page="forward_data.jsp">
<jsp:param value="5" name="num"/>
</jsp:forward>
</body>
</html>
forward_data.jsp
<%@ 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>
<%
int num= Integer.parseInt(request.getParameter("num"));
for(int i=1;i<=9;i++){
out.println(num+"*"+i+"="+(num*i)+"<br>");
}
%>
</body>
</html>

실습문제8-1.pdf
cookie.jsp
<%@ 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>
<form method="get" action="cookie_process.jsp">
아 이 디:
<input type="text" name="id" size="20" maxlength="20">
비밀번호:
<input type="text" name="pw" size="20" maxlength="20">
<input type="submit" value="전송">
</form>
</body>
</html>
cookie_process.jsp
<%@page import="java.net.URLEncoder"%>
<%@ 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= request.getParameter("id");
String pw= request.getParameter("pw");
String s_id = "admin";
String s_pw = "admin1234";
Cookie cookie_id= null;
if(s_id.equals(id)&&s_pw.equals(pw)){
cookie_id= new Cookie("userId",id);
cookie_id.setMaxAge(60*60);
cookie_id.setPath("/");
response.addCookie(cookie_id);
response.sendRedirect("welcome.jsp");
}else{
response.sendRedirect("cookie.jsp");
}
%>
</body>
</html>
welcome.jsp
<%@ 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= null;
Cookie[] cookies = request.getCookies();
for(int i=0;i<cookies.length;i++){
if(cookies[i].getName().equals("userId")){
%><h4><%= cookies[i].getValue()%>님 반갑습니다. </h4><%
break;
}
}%>
<p><a href="cookie_out.jsp">로그아웃</a></p>
</body>
</html>
cookie_out.jsp
<%@ 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>
<%
Cookie[] cookies = request.getCookies();
for (int i = 0; i < cookies.length; i++) {
cookies[i].setMaxAge(0);
cookies[i].setPath("/");
response.addCookie(cookies[i]);
}
response.sendRedirect("cookie.jsp");
%>
</body>
</html>