티스토리 뷰
productrepository.java
package dao;
import java.util.ArrayList;
import dto.product;
public class productrepository {
private ArrayList<product> listOfProducts = new ArrayList<product>();
public productrepository() {
product phone = new product("P1234", "iphone 6s", 800000);
phone.setDescription("4.7-inch, 1334X750 Renina HD idsplay, 8-megapixel iSight Camera");
phone.setCategory("Smart Phone");
phone.setManufacturer("Apple");
phone.setUnitsInStock(1000);
phone.setCondition("new");
product notebook = new product("P1235", "LG PC 그램", 1500000);
notebook.setDescription("13.3-inch, IPS LED display, 5rd Generation Intel Core processors");
notebook.setCategory("Notebook");
notebook.setManufacturer("LG");
notebook.setUnitsInStock(1000);
notebook.setCondition("Refurbished");
product tablet = new product("P1236", "Galaxy Tab S", 900000);
tablet.setDescription("212.8*125.6*6.6mm, Super AMOLED display, Octa-Core processor");
tablet.setCategory("Tablet");
tablet.setManufacturer("Samsung");
tablet.setUnitsInStock(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 productBtId=null;
for(int i=0; i<listOfProducts.size(); i++) {
product product = listOfProducts.get(i);
if(product != null && product.getProductId() != null && product.getProductId().equals(productId)) {
productBtId = product;
break;
}
}
return productBtId;
}
}
products.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.util.ArrayList" %>
<%@ page import="dto.product" %>
<jsp:useBean id="productDAO" class="dao.productrepository" scope="session"/>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>
<body>
<jsp:include page="menu.jsp" />
<div class="jumbotron">
<div class="container">
<h1 class="display-3">상품 목록</h1>
</div>
</div>
<%
ArrayList<product> listOfProducts = productDAO.getAllProducts();
%>
<div class="container">
<div class="row" align="center">
<%
for(int i=0; i<listOfProducts.size(); i++){
product product = listOfProducts.get(i);
%>
<div class="col-md-4">
<h3><%=product.getPname() %></h3>
<p><%=product.getDescription() %>
<p><%=product.getUnitprice() %>원
<p> <a href="./product.jsp?id=<%=product.getProductId() %>"
class="btn btn-secondary" role="button" >상세 정보 »></a>
</div>
<%
}
%>
</div>
<hr>
</div>
<%= productDAO %>
<jsp:include page="footer.jsp"/>
</body>
</html>
product.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import = "dto.product" %>
<jsp:useBean id = "productDAO" class="dao.productrepository" scope="session" />
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<meta charset="EUC-KR">
<title>상품 상세 정보</title>
</head>
<body>
<jsp:include page="menu.jsp"></jsp:include>
<div class="jumbotron">
<div class="container">
<h1 class="display-3">상품 정보</h1>
</div>
</div>
<%
String id = request.getParameter("id");
product product = productDAO.getProductById(id);
%>
<div class="container">
<div class="row">
<div class="col-md-6">
<h3><%=product.getPname() %></h3>
<p><%=product.getDescription() %>
<p> <b>상품 코드 : </b><span class="badge badge-danger">
<%=product.getProductId()%></span>
<p> <b>제조사</b> : <%=product.getManufacturer() %>
<p> <b>분류</b> : <%=product.getCategory() %>
<p> <b>재고 수</b> : <%=product.getUnitsInStock() %>
<h4><%=product.getUnitprice() %>원</h4>
<p> <a href="#" class="btn btn-info"> 상품 주문 »</a>
<a href="./products.jsp" class="btn btn-secondary"> 상품 목록 »</a>
</div>
</div>
</div>
<jsp:include page="footer.jsp"></jsp:include>
</body>
</html>
'코딩 > JSP' 카테고리의 다른 글
[9주 3일차] 폼 태그 (1) | 2023.12.06 |
---|---|
[9주 3일차] 내장 객체 2 (2) | 2023.12.06 |
[9주차 2일] JSP (1) | 2023.12.05 |
[9주 1일차] 내장 객체 (0) | 2023.12.04 |
웹쇼핑몰 (0) | 2023.12.01 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday