JSP

 

ProductDetailAction

package net.macaronics.web.controll;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import net.macaronics.web.controll.action.Action;
import net.macaronics.web.dao.ProductDAO;
import net.macaronics.web.dto.ProductVO;

public class ProductDetailAction implements Action {

	final Logger logger =LogManager.getLogger(ProductDetailAction.class);
	
	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) throws
			ServletException, IOException {
		
		String url="product/productDetail.jsp";
		String pseq= request.getParameter("pseq").trim();
		
		ProductDAO productDAO =ProductDAO.getInstance();
	
		request.setAttribute("productVO", productDAO.getProduct(pseq)); //1개의 상품
		request.setAttribute("bannerProduct", productDAO.bannerProduct()); //배너 상품 4개
		
		RequestDispatcher dispatcher=request.getRequestDispatcher(url);
		dispatcher.forward(request, response);
		
	}

	
	
}

 

 

ActionFactory

package net.macaronics.web.controll.factory;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import net.macaronics.web.controll.IndexAction;
import net.macaronics.web.controll.ProductDetailAction;
import net.macaronics.web.controll.action.Action;

public class ActionFactory {
	final Logger logger =LogManager.getLogger(ActionFactory.class);
	//싱글톤설정
	private static ActionFactory instance;
	private ActionFactory(){
		super();
	}
	public static ActionFactory getInstance(){
		if(instance==null){
			instance=new ActionFactory();
		}
		return instance;
	}
	
	
	//command 에서 넘어온 파라미터 값이 존재하면 실행
	//즉 ,존재하면 url 만 실행된다. 
	public Action getAction(String command){
		Action action=null;
		logger.info("ActionFactory : {}  ", command);
		
		if(command.equals("index")) action=new IndexAction();  
		else if(command.equals("product_detail")) action=new ProductDetailAction();
		
		return action;
	}
	
	
}

 

productDetail.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>  
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>   
<!DOCTYPE html>
<html>
<head>
<jsp:include page="../include/Header.jsp" />  
 </head> 
<body>
<jsp:include page="../include/HeaderMenu.jsp" />

  <!-- product category -->
  <section id="aa-product-details">
    <div class="container">
      <div class="row">
        <div class="col-md-12">
          <div class="aa-product-details-area">
            <div class="aa-product-details-content">
              <div class="row">
                <!-- Modal view slider -->
                <div class="col-md-5 col-sm-5 col-xs-12">                              
                  <div class="aa-product-view-slider">                                
                    <div id="demo-1" class="simpleLens-gallery-container">
                      <div class="simpleLens-container">
                        <div class="simpleLens-big-image-container"><a data-lens-image="images/${productVO.image }" class="simpleLens-lens-image">
                        <img src="images/${productVO.image }" class="simpleLens-big-image">
                        </a></div>
                      </div>
                    </div>
                  </div>
                </div>
              
              
                <!-- Modal view content -->
                <div class="col-md-7 col-sm-7 col-xs-12">
                  <form action="">
                  <div class="aa-product-view-content">
                    <h3>${productVO.name}</h3>
                    <div class="aa-price-block">
                      <span class="aa-product-view-price"><fmt:formatNumber pattern="#,### 원" value="${productVO.price2}"/></span>
                      
                    </div>
                   <p>${productVO.content}</p>
                    <h4>수량</h4>
                    <div class="aa-prod-view-size">
                     <input type="text" name="quantity" value="1" >
					<input type="hidden" name="pseq" value="${productVO.pseq}">		
                    </div>
                    
          
                    <div class="aa-prod-view-bottom">
                      <a  class="aa-add-to-cart-btn" href="#" onclick="">장바구니에 담기</a>
                      <a class="aa-add-to-cart-btn" href="#"  >즉시구매</a>
                      <a class="aa-add-to-cart-btn" href="#"  >취소</a>
                    </div>
                  </div>
                  
                  </form>       
                </div>
              </div>
            </div>
            
            

          
            <!-- Related product -->
            <div class="aa-product-related-item">
              <h3>메인 상품</h3>
              <ul class="aa-product-catg aa-related-item-slider">
		   
		   
		   	<c:forEach items="${bannerProduct }" var="productVO">
                        <li>
                          <figure>
                            <a class="aa-product-img" href="MacaronicsServlet?command=product_detail&pseq=${productVO.pseq}"><img src="images/${productVO.image}" alt="신상품 이미지" width="250" height="300"></a>
                            <a class="aa-add-card-btn"href="#"><span class="fa fa-shopping-cart"></span>장바구니에 담기</a>
                            <figcaption>
                              <h4 class="aa-product-title"><a href="#">${productVO.name}</a></h4>
                              <span class="aa-product-price"><fmt:formatNumber pattern="#,### 원" value="${productVO.price2}"/></span>
                            </figcaption>
                          </figure>                          
                          <div class="aa-product-hvr-content">
                           <a href="#" data-toggle="tooltip" data-placement="top" title="Add to Wishlist"><span class="fa fa-heart-o"></span></a>
                            <a href="#" data-toggle="tooltip" data-placement="top" title="Compare"><span class="fa fa-exchange"></span></a>
                            <a href="#" data-toggle2="tooltip" data-placement="top" title="Quick View" data-toggle="modal" data-target="#quick-view-modal"><span class="fa fa-search"></span></a>
                          </div>
                        </li>
                        <!-- start single product item -->
                      </c:forEach> 
                                                                                   
              </ul>     
           
            </div>  
          </div>
        </div>
      </div>
    </div>
  </section>
  <!-- / product category -->



<jsp:include page="../include/Footer.jsp" />

 

실행 화면

 

제작 : macaronics.net - Developer  Jun Ho Choi

소스 :  https://github.com/braverokmc79/jsp_sin

루트 설정( http://macaronics.net/index.php/m01/jsp/view/1352)    및 server.xml  에서 DB 컨넥션 설정은 필수 설정이다.

 

 

 

jsp

 

about author

PHRASE

Level 60  라이트

과거의 일을 충분히 소화하고 그것을 토대로 하여 미래에 대한 새로운 사고 방법을 도출해 내야 하는 것이다. 온고지신(溫故知新). -논어

댓글 ( 4)

댓글 남기기

작성