![](https://images.velog.io/images/ansalstmd/post/7d79b331-c808-4116-a7b8-95c6b61fe873/image.png
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3>회원 가입</h3>
<form action="#" name="member" method="post">
<p> 아이디 : <input type="text" name="id"> <input type="button" value="아이디 중복 검사"></p>
<p>비밀번호 : <input type="password" name="password"></p>
<p>이름 : <input type="text" name="name"></p>
<p>
연락처 : <input type="text" maxlength="4" size="4" name="phone1">
- <input type="text" maxlength="4" size="4" name="phone2">
- <input type="text" maxlength="4" size="4" name="phone3">
</p>
<p>
성별 : <input type="radio" name="sex" value="남성" checked>남성
<input type="radio" name="sex" value="여성">여성
</p>
<p>
취미 : 독서 <input type="checkbox" name="hobby1" checked>
운동 <input type="checkbox" name="hobby2">
영화 <input type="checkbox" name="hobby3">
</p>
<p>
<input type="submit" value="가입하기">
<input type="reset" value="다시 쓰기">
</p>
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3>회원 가입</h3>
<form action="#" name="member" method="post">
<p> 아이디 : <input type="text" name="id"> <input type="button" value="아이디 중복 검사"></p>
<p>비밀번호 : <input type="password" name="password"></p>
<p>이름 : <input type="text" name="name"></p>
<p>
연락처 : <select name="phone1">
<option value="010">010</option>
<option value="011">011</option>
<option value="016">016</option>
<option value="017">017</option>
<option value="019">019</option>
</select>
- <input type="text" maxlength="4" size="4" name="phone2">
- <input type="text" maxlength="4" size="4" name="phone3">
</p>
<p>
성별 : <input type="radio" name="sex" value="남성" checked>남성
<input type="radio" name="sex" value="여성">여성
</p>
<p>
취미 : 독서 <input type="checkbox" name="hobby1" checked>
운동 <input type="checkbox" name="hobby2">
영화 <input type="checkbox" name="hobby3">
</p>
<p>
<input type="submit" value="가입하기">
<input type="reset" value="다시 쓰기">
</p>
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3>회원 가입</h3>
<form action="#" name="member" method="post">
<p> 아이디 : <input type="text" name="id"> <input type="button" value="아이디 중복 검사"></p>
<p>비밀번호 : <input type="password" name="password"></p>
<p>이름 : <input type="text" name="name"></p>
<p>
연락처 : <select name="phone1">
<option value="010">010</option>
<option value="011">011</option>
<option value="016">016</option>
<option value="017">017</option>
<option value="019">019</option>
</select>
- <input type="text" maxlength="4" size="4" name="phone2">
- <input type="text" maxlength="4" size="4" name="phone3">
</p>
<p>
성별 : <input type="radio" name="sex" value="남성" checked>남성
<input type="radio" name="sex" value="여성">여성
</p>
<p>
취미 : 독서 <input type="checkbox" name="hobby1" checked>
운동 <input type="checkbox" name="hobby2">
영화 <input type="checkbox" name="hobby3">
</p>
<p>
<textarea name="comment" cols="30" rows="3" placeholder="가입 인사를 입력해 주세요">
</textarea>
</p>
<p>
<input type="submit" value="가입하기">
<input type="reset" value="다시 쓰기">
</p>
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3>회원 가입</h3>
<form action="form04_process.jsp" name="member" method="post">
<p> 아이디 : <input type="text" name="id"> <input type="button" value="아이디 중복 검사"></p>
<p>비밀번호 : <input type="password" name="password"></p>
<p>이름 : <input type="text" name="name"></p>
<p>
연락처 : <select name="phone1">
<option value="010">010</option>
<option value="011">011</option>
<option value="016">016</option>
<option value="017">017</option>
<option value="019">019</option>
</select>
- <input type="text" maxlength="4" size="4" name="phone2">
- <input type="text" maxlength="4" size="4" name="phone3">
</p>
<p>
성별 : <input type="radio" name="sex" value="남성" checked>남성
<input type="radio" name="sex" value="여성">여성
</p>
<p>
취미 : 독서 <input type="checkbox" name="hobby1" checked>
운동 <input type="checkbox" name="hobby2">
영화 <input type="checkbox" name="hobby3">
</p>
<p>
<textarea name="comment" cols="30" rows="3" placeholder="가입 인사를 입력해 주세요">
</textarea>
</p>
<p>
<input type="submit" value="가입하기">
<input type="reset" value="다시 쓰기">
</p>
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
request.setCharacterEncoding("UTF-8");
String id = request.getParameter("id");
String password = request.getParameter("password");
String name = request.getParameter("name");
String phone1 = request.getParameter("phone1");
String phone2 = request.getParameter("phone2");
String phone3 = request.getParameter("phone3");
String sex = request.getParameter("sex");
String hobby1 = request.getParameter("hobby1");
String hobby2 = request.getParameter("hobby2");
String hobby3 = request.getParameter("hobby3");
String comment = request.getParameter("comment");
%>
<p> 아이디 : <%=id %></p>
<p> 비밀번호 : <%=password %></p>
<p> 이름 : <%=name %></p>
<p> 휴대폰 : <%=phone1 %>-<%=phone2 %>-<%=phone3 %></p>
<p> 성별 : <%=sex %></p>
<p> 취미 : <%=hobby1 %> <%=hobby2 %> <%=hobby3 %></p>
<p> 가입인사 : <%=comment %></p>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3>회원 가입</h3>
<form action="form04_process.jsp" name="member" method="post">
<p> 아이디 : <input type="text" name="id"> <input type="button" value="아이디 중복 검사"></p>
<p>비밀번호 : <input type="password" name="password"></p>
<p>이름 : <input type="text" name="name"></p>
<p>
연락처 : <select name="phone1">
<option value="010">010</option>
<option value="011">011</option>
<option value="016">016</option>
<option value="017">017</option>
<option value="019">019</option>
</select>
- <input type="text" maxlength="4" size="4" name="phone2">
- <input type="text" maxlength="4" size="4" name="phone3">
</p>
<p>
성별 : <input type="radio" name="sex" value="남성" checked>남성
<input type="radio" name="sex" value="여성">여성
</p>
<p>
취미 : 독서 <input type="checkbox" name="hobby" value="독서" checked>
운동 <input type="checkbox" name="hobby" value="운동">
영화 <input type="checkbox" name="hobby" value="영화">
</p>
<p>
<textarea name="comment" cols="30" rows="3" placeholder="가입 인사를 입력해 주세요">
</textarea>
</p>
<p>
<input type="submit" value="가입하기">
<input type="reset" value="다시 쓰기">
</p>
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
request.setCharacterEncoding("UTF-8");
String id = request.getParameter("id");
String password = request.getParameter("password");
String name = request.getParameter("name");
String phone1 = request.getParameter("phone1");
String phone2 = request.getParameter("phone2");
String phone3 = request.getParameter("phone3");
String sex = request.getParameter("sex");
String[] hobbys = request.getParameterValues("hobby");
String comment = request.getParameter("comment");
%>
<p> 아이디 : <%=id %></p>
<p> 비밀번호 : <%=password %></p>
<p> 이름 : <%=name %></p>
<p> 휴대폰 : <%=phone1 %>-<%=phone2 %>-<%=phone3 %></p>
<p> 성별 : <%=sex %></p>
<p> 취미 : <%
if (hobbys != null) {
for(String hoby : hobbys) {
out.println(" "+hoby);
}
}
%>
</p>
<p> 가입인사 : <%=comment %></p>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3>회원 가입</h3>
<form action="form06_process.jsp" name="member" method="post">
<p> 아이디 : <input type="text" name="id"> <input type="button" value="아이디 중복 검사"></p>
<p>비밀번호 : <input type="password" name="password"></p>
<p>이름 : <input type="text" name="name"></p>
<p>
연락처 : <select name="phone1">
<option value="010">010</option>
<option value="011">011</option>
<option value="016">016</option>
<option value="017">017</option>
<option value="019">019</option>
</select>
- <input type="text" maxlength="4" size="4" name="phone2">
- <input type="text" maxlength="4" size="4" name="phone3">
</p>
<p>
성별 : <input type="radio" name="sex" value="남성" checked>남성
<input type="radio" name="sex" value="여성">여성
</p>
<p>
취미 : 독서 <input type="checkbox" name="hobby" value="독서" checked>
운동 <input type="checkbox" name="hobby" value="운동">
영화 <input type="checkbox" name="hobby" value="영화">
</p>
<p>
<textarea name="comment" cols="30" rows="3" placeholder="가입 인사를 입력해 주세요">
</textarea>
</p>
<p>
<input type="submit" value="가입하기">
<input type="reset" value="다시 쓰기">
</p>
</form>
</body>
</html>
<%@page import="java.util.Enumeration"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<table border="1" >
<tr>
<th>요청 파라미터 이름</th>
<th>요청 파라미터 값</th>
</tr>
<%
request.setCharacterEncoding("UTF-8");
Enumeration paramNames = request.getParameterNames();
while(paramNames.hasMoreElements()) {
String name = (String) paramNames.nextElement();
out.print("<tr><td>"+name+"</td>\n");
String paramValue = request.getParameter(name);
out.print("<td>"+paramValue+"</td></tr>\n");
}
%>
</table>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>상품 등록</title>
<style>
.inputRow {
margin: 15px 0px;
display: flex;
align-items : center;
}
.inputRow label {
width : 150px;
}
.inputRow input, .inputRow textarea {
font-size: 1.3rem;
}
.inputRow input.btn {
font-size: 1rem;
padding : 5px 15px;
}
</style>
</head>
<body>
<jsp:include page="header.jsp" />
<div class="main">
<div class="banner">
<div class="container">
<h1>상품 등록</h1>
</div>
</div>
<div class="content">
<div class="container">
<form name="newProduct" action="./processAddProduct.jsp"
class="form-horizontal" method="post">
<div class="inputRow">
<label for="productId">상품 코드</label> <input type="text"
name="productId" id="productId">
</div>
<div class="inputRow">
<label for="name">상품 명</label> <input type="text" name="name" id ="name">
</div>
<div class="inputRow">
<label for="unitPrice">가격</label> <input type="text" name="unitPrice" id="unitPrice">
</div>
<div class="inputRow">
<label for="description">상세 정보</label>
<textarea name="description" cols="50" rows="2" id="description">
</textarea>
</div>
<div class="inputRow">
<label for="manufacturer">제조사</label> <input type="text" name="manufacturer" id="manufacturer">
</div>
<div class="inputRow">
<label for="category">분류</label> <input type="text" name="category" id="category">
</div>
<div class="inputRow">
<label for="unitStock">재고 수</label> <input type="text" name="unitStock" id="unitStock">
</div>
<div class="inputRow">
<label>상태</label>
<label><input type="radio" name="condition" value="New"> 신규 제품</label>
<label><input type="radio" name="condition" value="Old"> 중고 제품</label>
<label><input type="radio" name="condition" value="Refurbished"> 재생 제품</label>
</div>
<div class="inputRow">
<input type="submit" value="등록" class="btn btn-secondary">
</div>
</form>
<hr>
</div>
</div>
</div>
<jsp:include page="footer.jsp" />
</body>
</html>
package dao;
import java.util.ArrayList;
import dto.Product;
public class ProductRepository {
private ArrayList<Product> listOfProducts = new ArrayList<Product>();
private static ProductRepository instance = new ProductRepository();
public static ProductRepository getInstance() {
return instance;
}
public ProductRepository() {
Product phone = new Product("P1234", "iPhone 6s", 800000);
phone.setDescription("4.7-inch, 1334X750 Renina HD display, 8-megapixel iSight Camera");
phone.setCategory("Smart Phone");
phone.setManufacturer("Apple");
phone.setUnitInStock(1000);
phone.setCondition("New");
Product notebook = new Product("P1235", "LG PC 그램", 1500000);
notebook.setDescription("13.3-inch, IPS LED display, 5rd Generation notebook. Inter Core processors");
notebook.setCategory("Notebook");
notebook.setManufacturer("LG");
notebook.setUnitInStock(1000);
notebook.setCondition("Refurbished");
Product tablet = new Product("P1236", "Galaxy Tab S", 900000);
tablet.setDescription("212.8*125.6*6.6mm, Super AMOLEED display, Octa-Core processor");
tablet.setCategory("Tablet");
tablet.setManufacturer("Samsum");
tablet.setUnitInStock(1000);
tablet.setCondition("Old");
listOfProducts.add(phone);
listOfProducts.add(notebook);
listOfProducts.add(tablet);
}
public ArrayList<Product> getAllProducts() {
return listOfProducts;
}
public Product getProductById(String productId) {
Product productById = null;
for (int i = 0; i < listOfProducts.size(); i++) {
Product product = listOfProducts.get(i);
if(product != null && product.getProductId() != null && product.getProductId().equals(productId)){
productById = product;
break;
}
}
return productById;
}
public void addProduct(Product product) {
listOfProducts.add(product);
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="dto.Product" %>
<%@ page import="dao.ProductRepository" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
request.setCharacterEncoding("UTF-8");
String productId = request.getParameter("productId");
String name = request.getParameter("name");
String unitPrice = request.getParameter("unitPrice");
String description = request.getParameter("description");
String manufacturer = request.getParameter("manufacturer");
String category = request.getParameter("category");
String unitInStock = request.getParameter("unitInStock");
String condition = request.getParameter("condition");
Integer price;
if(unitPrice.isEmpty())
price = 0;
else
price = Integer.parseInt(unitPrice);
long stock;
if(unitInStock.isEmpty())
stock = 0;
else
stock = Long.parseLong(unitInStock);
ProductRepository dao = ProductRepository.getInstance();
Product newProduct = new Product();
newProduct.setProductId(productId);
newProduct.setPname(name);
newProduct.setUnitPrice(price);
newProduct.setDescription(description);
newProduct.setManufacturer(manufacturer);
newProduct.setCategory(category);
newProduct.setUnitInStock(stock);
newProduct.setCondition(condition);
dao.addProduct(newProduct);
response.sendRedirect("products.jsp");
%>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.util.ArrayList"%>
<%@ page import="dto.Product"%>
<%@ page import="dao.ProductRepository" %>
<jsp:useBean id="productDAO" class="dao.ProductRepository"
scope="session" />
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>상품 목록</title>
<style>
.main .content .row {
display: flex;
justify-content: space-around;
align-items: center;
flex-wrap : wrap;
}
.main .content .row .column {
width: 300px;
display: flex;
flex-direction: column;
justify-content: center;
margin: 15px 0;
}
.main .content .row .column h3, .main .content .row .column p {
text-align: center;
padding: 10px;
}
.main .content .row .column h3 {
font-size: 1.7rem;
font-weight: 400;
}
</style>
<%!String greenting = "상품목록";%>
</head>
<body>
<jsp:include page="header.jsp" />
<div class="main">
<div class="banner">
<div class="container">
<h1><%=greenting%></h1>
</div>
</div>
<div class="content">
<%
ProductRepository dao = ProductRepository.getInstance();
ArrayList<Product>listOfProducts = dao.getAllProducts();
%>
<div class="container">
<div class="row">
<%
for (int i = 0; i < listOfProducts.size(); i++) {
Product product = listOfProducts.get(i);
%>
<div class="column">
<h3><%=product.getPname()%></h3>
<p><%=product.getDescription()%></p>
<p><%=product.getUnitPrice()%>원
</p>
<p>
<a href="./product.jsp?id=<%=product.getProductId()%>"
class="btn" role="button">상세 정보»</a>
</div>
<%
}
%>
</div>
<hr>
</div>
</div>
</div>
<jsp:include page="footer.jsp" />
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="dto.Product"%>
<%@ page import="dao.ProductRepository" %>
<jsp:useBean id="productDAO" class="dao.ProductRepository"
scope="session" />
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>상품 상세 정보</title>
<style>
.content .row {
padding : 30px 0;
}
.content h3, .content p, .content h4 {
margin : 25px 0;
}
.content h3 {
margin-bottom : 5px;
}
.content .description {
margin-top : 5px;
}
.content .badge {
background-color : #f00;
color : #fff;
border-radius : 5px;
}
</style>
</head>
<body>
<jsp:include page="header.jsp" />
<div class="main">
<div class="banner">
<div class="container">
<h1>상품 정보</h1>
</div>
</div>
<%
String id = request.getParameter("id");
ProductRepository dao = ProductRepository.getInstance();
Product product = dao.getProductById(id);
%>
<div class="content">
<div class="container">
<div class="row">
<h3><%=product.getPname()%></h3>
<p class="description"><%=product.getDescription()%></p>
<p>
<b>상품 코드 : </b><span class="badge"><%=product.getProductId()%></span>
<p>
<b>제조사</b> :
<%=product.getManufacturer()%></p>
<p>
<b>분류</b> :
<%=product.getCategory()%></p>
<p>
<b>재고 수</b> :
<%=product.getUnitInStock()%>
</p>
<h4><%=product.getUnitPrice()%>원</h4>
<p>
<a href="#" class="btn btn-secondary">상품 주문 »</a>
<a href="./products.jsp" class="btn">상품 목록 »</a>
</p>
</div>
<hr>
</div>
</div>
</div>
<jsp:include page="footer.jsp" />
</body>
</html>