JSP

 

 

 

OrderDetailAction

package net.macaronics.web.controll;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

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

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

import net.macaronics.web.controll.action.Action;
import net.macaronics.web.dao.OrderDAO;
import net.macaronics.web.dto.MemberVO;
import net.macaronics.web.dto.OrderVO;

public class OrderDetailAction implements Action{

	private static final Logger logger =LogManager.getLogger(OrderDetailAction.class);
	
	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String url ="mypage/orderDetail.jsp";
		
		HttpSession session=request.getSession();
		MemberVO loginUser=(MemberVO)session.getAttribute("loginUser");
		if(loginUser==null){
			url="MacaronicsServlet?command=login_form";
		}else{
			int oseq =Integer.parseInt(request.getParameter("oseq"));
			OrderDAO orderDAO =OrderDAO.getInstance();
			List<OrderVO> orderList=orderDAO.listOrderById(loginUser.getId(), "%", oseq);
			
			logger.info(" OrderDetailAction -  orderList  {}" , orderList.toString());
			
			
			int orderTotalPrice=0;
			OrderVO orderDetail =new OrderVO();
			int i=0;
			for(OrderVO ovo : orderList){
				orderTotalPrice =ovo.getPrice2()*ovo.getQuantity();
				if(i==0){
					orderDetail.setIndate(ovo.getIndate());
					orderDetail.setOseq(ovo.getOseq());
					orderDetail.setMname(ovo.getMname());
					orderDetail.setPname(ovo.getPname() + " 외 " + orderList.size() + " 건");
				}
				i++;
			}
			
			request.setAttribute("orderDetail", orderDetail);
			request.setAttribute("orderList", orderList);
			request.setAttribute("orderTotalPrice", orderTotalPrice);
			
		}
		request.getRequestDispatcher(url).forward(request, response);
	}

	
	
}

 

 

mypage.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" />


  <!-- catg header banner section -->
  <section id="aa-catg-head-banner">
   <img src="/dailyShop/img/slider/4.jpg" alt="fashion img" height="300" style="margin-left: auto; margin-right: auto; display: block;">
   <div class="aa-catg-head-banner-area">
     <div class="container">
     </div>
   </div>
  </section>
  <!-- / catg header banner section -->


  <!-- product category -->
  <section id="aa-product-category">
    <div class="container">
      <div class="row">
        <div class="col-lg-9 col-md-9 col-sm-8 col-md-push-3">
          <div class="aa-product-catg-content">
          		<h3 class="text-center">My Page (${title })</h3>
            <div class="aa-product-catg-body">
              <div class="table-responsive">
              <table class="table table-striped">
              	 <tr class="danger">
              	   <th>주문일자</th>
              	   <th>주문번호</th>
              	   <th>상품명</th>
              	   <th>결제 금액</th>
              	   <th>주문 상세</th>
              	 </tr>
              	 <tr>
              	   <c:forEach items="${orderList}" var="orderVO">
              	   	 <tr>
              	   	  <td><fmt:formatDate value="${orderVO.indate }" type="date" /></td>
              	   	  <td>${orderVO.oseq }</td>
              	   	  <td>${orderVO.pname }</td>
              	   	  <td><fmt:formatNumber value="${orderVO.price2 }" type="currency" /></td>
              	   	  <td><a href="MacaronicsServlet?command=order_detail&oseq=${orderVO.oseq}" class="btn btn-warning">조회</a></td>
              	   	 </tr>
              	   </c:forEach>
              	 </tr>
              	            
              </table>
              </div>
                
            </div>
            
            <div class="text-center">
            	<input type="button" value="쇼핑 계속하기" class="btn btn-primary"
            	 onclick="location.href='MacaronicsServlet?command=index'" >
            </div>

          </div>
        </div>
        
        
        <div class="col-lg-3 col-md-3 col-sm-4 col-md-pull-9">
          <aside class="aa-sidebar">
            <!-- single sidebar -->
            <div class="aa-sidebar-widget">
              <h3>나의 페이지</h3>
              <ul class="aa-catg-nav">      
             <li><a href="MacaronicsServlet?command=cart_list">장바구니(cart)내역</a></li>
              <li><a href="MacaronicsServlet?command=mypage">진행중인 주문내역</a></li>
              <li><a href="MacaronicsServlet?command=order_all">총 주문내역</a></li>              
              </ul>
            </div>
         </aside>         
        </div>
       
       
      </div>
    </div>
  </section>
  <!-- / product category -->



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

 

 

	//주문 목록 불러오기
	public List<OrderVO> listOrderById(String id, String result, int oseq){
		List<OrderVO> orderList=new ArrayList<>();
		try{
			sqlSession =MybatisService.getFactory().openSession();
			Map<String, Object> map =new HashMap<>();
			map.put("id", id);
			map.put("result", result);
			map.put("oseq", oseq);
			orderList=sqlSession.selectList("order.listOrderById" , map);
		}catch(Exception e){
			e.printStackTrace();
		}finally{
			MybatisService.sessionClose(sqlSession);
		}
		return orderList;
	}

 

 

	<select id="listOrderById" resultType="net.macaronics.web.dto.OrderVO">
		select * from order_view where id=#{id} and result like '%'||#{result} ||'%' and oseq=#{oseq}
	</select>

 

제작 : macaronics.net - Developer  Jun Ho Choi

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

 

${request.getContextPath() } 처리를 안한 부분이 있으므로 

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

 

 

 

jsp

 

about author

PHRASE

Level 60  라이트

젊은 시절은 다시 오지 않고, 하루에 새벽이 두 번 있지 않다. 때가 되면 마땅히 학문에 힘쓸지니, 세월은 사람을 기다려주지 않는다. -도연명

댓글 ( 4)

댓글 남기기

작성