개발로그필름
[쉽게 배우는 JSP 웹 프로그래밍] 4장 웹 쇼핑몰 예제 코드 본문
728x90
반응형
SMALL
WebMarket/src/dto/Product.java
package dto;
import java.io.Serializable;
public class Product implements Serializable {
// private static final long serialVersionUID = -427474700572038677000L;;
private String productId; // 상품 아이디
private String pname; // 상품명
private Integer unitPrice; // 상품 가격
private String description; // 상품 설명
private String manufacturer; // 제조사
private String category; // 분류
private long unitsInStock; // 재고 수
private String condition; // 신상품 or 중고품 or 재생품
public Product() {
super();
}
public Product(String productId, String pname, Integer unitPrice) {
this.productId = productId;
this.pname = pname;
this.unitPrice = unitPrice;
}
public String getProductId() {
return productId;
}
public void setProductId(String productId) {
this.productId = productId;
}
public String getPname() {
return pname;
}
public void setPname(String pname) {
this.pname = pname;
}
public Integer getUnitPrice() {
return unitPrice;
}
public void setUnitPrice(Integer unitPrice) {
this.unitPrice = unitPrice;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getManufacturer() {
return manufacturer;
}
public void setManufacturer(String manufacturer) {
this.manufacturer = manufacturer;
}
public String getCategory() {
return category;
}
public void setCategory(String category) {
this.category = category;
}
public long getUnitsInStock() {
return unitsInStock;
}
public void setUnitsInStock(long unitsInStock) {
this.unitsInStock = unitsInStock;
}
public String getCondition() {
return condition;
}
public void setCondition(String condition) {
this.condition = condition;
}
}
WebMarket/src/dao/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 display, 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;
}
}
WebMarket/WebContent/products.jsp
<%@ page contentType="text/html; charset=utf-8"%>
<%@ page import="java.util.ArrayList"%>
<%@ page import="dto.Product" %>
<jsp:useBean id="productDAO" class="dao.ProductRepository" scope="session" />
<html>
<head>
<link rel = "stylesheet"
href = "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<title>상품 목록</title>
</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() %>원
</div>
<%
}
%>
</div>
<hr>
</div>
<jsp:include page="footer.jsp"/>
</body>
</html>
반응형
LIST
'IT > 쉽게 배우는 JSP 웹 프로그래밍' 카테고리의 다른 글
[쉽게 배우는 JSP 웹 프로그래밍] 7장 웹 쇼핑몰 예제 코드 (1) | 2022.11.30 |
---|---|
[쉽게 배우는 JSP 웹 프로그래밍] 6장 웹 쇼핑몰 예제 코드 (0) | 2022.11.29 |
[쉽게 배운는 JSP 웹 프로그래밍] 5장 웹 쇼핑몰 예제 코드 (0) | 2022.11.27 |
[쉽게 배우는 JSP 웹 프로그래밍] 3장 웹 소핑몰 예제 코드 (0) | 2022.11.22 |
[쉽게 배우는 JSP 웹 프로그래밍] 2장 웹 쇼핑몰 예제 코드 (0) | 2022.11.22 |
Comments