ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • [ERMaster] shoppingmall - category
    WEB/ERMaster 2022. 9. 10. 12:30

    카테고리별 상품

     

    else if(command.equals("category")) ac=new CategoryAction();
    package com.sam.shop.controller.action.product;
    
    import java.io.IOException;
    import java.util.ArrayList;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import com.sam.shop.controller.action.Action;
    import com.sam.shop.dao.ProductDao;
    import com.sam.shop.dto.ProductVO;
    
    public class CategoryAction implements Action {
    
    	@Override
    	public void execute(HttpServletRequest 
    			request, HttpServletResponse response)
    			throws ServletException, IOException {
    		
    		String kind=request.getParameter("kind");
    		ProductDao pdao=ProductDao.getInstance();
    		ArrayList<ProductVO> list=pdao.selectKindProductList(kind);
    		
    		request.setAttribute("productKindList", list);
    		String url="product/productKind.jsp";
    		request.getRequestDispatcher(url).forward(request, response);
    	}
    }

     

    ProductDao에 selectKindProductList 생성

    public ArrayList<ProductVO> selectKindProductList(String kind) {
    	ArrayList<ProductVO> list=new ArrayList<ProductVO>();
    	String sql="select * from product where kind=?";
    	con=Dbman.getConnection();
    	try {
    		pstmt=con.prepareStatement(sql);
    		pstmt.setString(1,kind);
    		rs=pstmt.executeQuery();
    		while(rs.next()) {
    			ProductVO pvo=new ProductVO();
    			pvo.setPseq(rs.getInt("pseq"));
    			pvo.setName(rs.getString("name"));
    			pvo.setPrice2(rs.getInt("price2"));
    			pvo.setImage(rs.getString("image"));
    			list.add(pvo);
    		}
    	} catch (SQLException e) {e.printStackTrace();
    	} finally {Dbman.close(con, pstmt, rs);}
    	return list;
    }
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <%@ include file="../header.jsp" %>
    <%@ include file="sub_image_menu.html" %>
    
    <article>
    	<h2>Item</h2>
    	<c:forEach items="${productKindList }" var="productVO">
    		<div id="item">
    			<a href="shop.do?command=productDetail&pseq=${productVO.pseq}">
    				<img src="product_images/${productVO.image }"/>
    				<h3>${productVO.name }</h3>
    				<p>${productVO.price2 }</p>
    			</a>
    		</div>
    	</c:forEach>
    	<div class="clear"></div>
    </article>
    
    <%@ include file="../footer.jsp" %>
    <div id="sub_img">
    	<img src="images/product/sub_img.jpg" 
    		style="border-radius:20px 20px 20px 20px;">
    </div>
    <div class="clear"></div>
    
    <nav id="sub_menu">
    	<ul>
    		<li><a href="shop.do?command=category&kind=1">Heels</a></li>
    		<li><a href="shop.do?command=category&kind=2">Boots</a></li>
    		<li><a href="shop.do?command=category&kind=3">Sandals</a></li>
    		<li><a href="shop.do?command=category&kind=4">Sneakers</a></li>
    		<li><a href="shop.do?command=category&kind=5">Sleeper</a></li>
    		<li><a href="shop.do?command=category&kind=6">On Sale</a></li>
    	</ul>
    </nav>
     

     

    상품 상세보기

    else if(command.equals("productDetail")) ac=new ProductDetailAction();
    package com.sam.shop.controller.action.product;
    
    import java.io.IOException;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import com.sam.shop.controller.action.Action;
    import com.sam.shop.dao.ProductDao;
    import com.sam.shop.dto.ProductVO;
    
    public class ProductDetailAction implements Action {
    
    	@Override
    	public void execute(HttpServletRequest request, 
    			HttpServletResponse response) 
    			throws ServletException, IOException {
    		
    		int pseq=Integer.parseInt(request.getParameter("pseq"));
    		ProductDao pdao=ProductDao.getInstance();
    		ProductVO pvo=pdao.getProduct(pseq);
    		
    		request.setAttribute("productVO", pvo);
    		String url="product/productDetail.jsp";
    		
    		request.getRequestDispatcher(url).forward(request, response);
    	}
    }

     

    ProductDao에 getProduct 생성

    public ProductVO getProduct(int pseq) {
    	ProductVO pvo=null;
    	String sql="select*from product where pseq=?";
    	con=Dbman.getConnection();
    	try {
    		pstmt=con.prepareStatement(sql);
    		pstmt.setInt(1,pseq);
    		rs=pstmt.executeQuery();
    		if(rs.next()) {
    			pvo=new ProductVO();
    			pvo.setPseq(rs.getInt("pseq"));
    			pvo.setName(rs.getString("name"));
    			pvo.setKind(rs.getString("kind"));
    			pvo.setPrice2(rs.getInt("price1"));
    			pvo.setPrice2(rs.getInt("price2"));
    			pvo.setPrice2(rs.getInt("price3"));
    			pvo.setContent(rs.getString("content"));
    			pvo.setImage(rs.getString("image"));
    			pvo.setUseyn(rs.getString("useyn"));
    			pvo.setBestyn(rs.getString("bestyn"));
    			pvo.setIndate(rs.getTimestamp("indate"));
    		}
    		
    	} catch (SQLException e) {e.printStackTrace();
    	} finally {Dbman.close(con, pstmt, rs);}
    	return pvo;
    }
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <%@ include file="../header.jsp" %>
    <%@ include file="sub_image_menu.html" %>
    
    <article>
    <div id="itemdetail" style="float:left;">
    	<h1>Item</h1>
    	<form method="post" name="formm">
    		<fieldset>
    			<legend>Item detail info</legend>
    			<span style="float:left; margin-right:20px;">
    				<img src="product_images/${productVO.image}"
    					style="border-radius:20px;"/></span>
    			<h2>${productVO.name }</h2>
    			<label>가격: </label><p>${productVO.price2}원</p>
    			<label>수량: </label>
    				<input type="text" name="quantity" size="2" 
    							value="1">
    				<input type="hidden" name="pseq"
    					 value="${productVO.pseq }"><br>
    		</fieldset>
    		<div class="clear"></div>
    		<div style="margin:0 auto;">
    			<h3 style="font-size:170%;">
    				${productVO.content}</h3></div>
    		<div class="clear"></div>
    		<div id="buttons">
    			<input type="button" value="장바구니에 담기" 
                    class="submit" onclick="go_cart();">
    			<input type="button" value="즉시 구매" class="submit"
    				onclick="go_order();">
    			<input type="button" value="뒤로" class="cancel"
    				onclick="history.go(-1);"></div>
    	</form>
    </div>
    </article>
    
    <%@ include file="../footer.jsp" %>

     

    'WEB > ERMaster' 카테고리의 다른 글

    [ERMaster] shoppingmall - order  (0) 2022.09.10
    [ERMaster] shoppingmall - cart  (0) 2022.09.10
    [ERMaster] shoppingmall - find ID, PW  (0) 2022.09.10
    [ERMaster] shoppingmall - update  (0) 2022.09.10
    [ERMaster] shoppingmall - login, logout, join  (0) 2022.09.10

    댓글

Designed by Tistory.