Shop [ 첫페이지 ]

양혜정·2024년 4월 28일
0

javascript_web

목록 보기
78/81

Properties

# index mapping information
/=common.controller.IndexController
/index.do=common.controller.IndexController

IndexController

  • AbstractController 클래스 extends
private ProductDAO pdao = null;

public IndexController(){
	pdao = new ProductDAO_imple();
}
// === Override === //
try{
	// === 모든 이미지 리스트 뽑기 === //
	List<ImageVO> imgList = pdao.imageSelectAll();
    request.setAttribute("imgList",imgList);
    
    super.setRedirect(false);
    super.setViewPage("/WEB-INF/index.jsp");
} catch(SQLException e){
	super.setRedirect(true);
    super.setViewPage(request.getContextPath() + "/error.do");
}

ErrorController

// === Override === //
super.setRedirect(false);
super.setViewPage("/WEB-INF-error.jsp");

DAO

// === 메인페이지 이미지 === //
List<ImageVO> imageSelectAll() throws SQLException;

DAO_imple

private DataSource ds;	// 아파치톰캣에서 제공하는 DB Connection Pool
private Connection conn;
private PreparedStatement pstmt;
private ResultSet rs;

// 기본생성자
public ProductDAO_imple(){
	try{
    	Context initContext = new InitialContext();
        Context envContext = (Context)initContext.lookup("java:/comp/env");
        ds = (DataSource)envContext.lookup("jdbc/myoracle");
    } catch(NamingException e){
    	e.printStackTrace();
    }	// end of try~catch--------------
}

// === 자원 반납 close 메소드 === //
private void close(){
	try{
    	if(rs != null){
        	rs.close();
            rs=null;
        }
        if(pstmt != null){
        	pstmt.close();
            pstmt=null;
        }
        if(conn != null){
        	conn.close();
            conn=null;
        }
    } catch(SQLException e){
    	e.printStackTrace();
    }	// end of try~catch--------------------
}	// end of private void close()-----------------

// === 상품이미지 파일명 조회 메소드 === //
@Override
public List<ImageVO> imageSelectAll() throws SQLException{
	List<ImageVO> imgList = new ArrayList<>();
    try{
    	conn = ds.getConnection();	// DB 와 연결
        String sql = " select imgno, imgfilename "
        	+ " from tbl_main_image "
            + " order by imgno asc ";
        pstmt = conn.prepareStatement(sql);
        rs = pstmt.executeQuery();
        while(rs.next()){
        	ImageVO imgvo = new ImageVO();
            imgvo.setImageno(rs.getInt("imgno"));
            imgvo.setImgfilename(rs.getString("imgfilename"));
            
            imgList.add(imgvo);
        }	// end of while-----------
    } finally{
    	close();
    }	// end of try~finally-----------
    return imgList;
}	// end of public List<ImageVO> imageSelectAll() throws SQLException----

JSP ( 정상 )

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String ctxPath = request.getContextPath();
%>

<%-- 직접 만든 CSS --%>
<link rel="stylesheet" type="text/css" href="<%= ctxPath%>/css/main/main.css" />

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

<div class="container">
	<div>
    	<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
        	<ol class="carousel-indicators">
            	<c:if test="${not empty requestScope.imgList}">
            		<c:forEach items="${requestScope.imgList}" varStatus="status">
                		<c:if test="${status.index == 0}">
                			<li data-target="#carouselExampleIndicators" data-slide-to="${status.index}" class="active"></li>
                		</c:if>
                		<c:if test="${status.index > 0}">
			  				<li data-target="#carouselExampleIndicators" data-slide-to="${status.index}" ></li>
			  			</c:if>
             		</c:forEach>
            	</c:if>
        	</ol>
            <div class="carousel-inner">
            	<c:if test="${not empty requestScope.imgList}">
			  		<c:forEach var="imgvo" items="${requestScope.imgList}" varStatus="status">
			  			<c:if test="${status.index == 0}">
			  				<div class="carousel-item active">
						    	<img src="<%= ctxPath %>/images/${imgvo.imgfilename}" class="d-block w-100" alt="..."> <!-- d-block 은 display: block; 이고  w-100 은 width 의 크기는 <div class="carousel-item active">의 width 100% 로 잡으라는 것이다. -->
						    	<%-- 상품명 컬럼이 있는 경우
						    	<div class="carousel-caption d-none d-md-block"> <!-- d-none 은 display : none; 이므로 화면에 보이지 않다가, d-md-block 이므로 d-md-block 은 width 가 768px이상인 것에서만 display: block; 으로 보여라는 말이다.  --> 
							  		<h5>Koala</h5>
							    	<p>Koala Content</p>
							  	</div>
							  	--%>
						   	</div>
			  			</c:if>
			  			<c:if test="${status.index > 0}">
			  				<div class="carousel-item">
						    	<img src="<%= ctxPath %>/images/${imgvo.imgfilename}" class="d-block w-100" alt="...">	      
						    </div>
			  			</c:if>
			  		</c:forEach>
			  	</c:if>
             </div>
             <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
			    <span class="carousel-control-prev-icon" aria-hidden="true"></span>
			    <span class="sr-only">Previous</span>
			  </a>
			  <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
			    <span class="carousel-control-next-icon" aria-hidden="true"></span>
			    <span class="sr-only">Next</span>
			  </a>
        </div>
        설명글
    </div>
</div>
<jsp:include page="footer.jsp" />

JSP ( Error 페이지 )

<%
	String ctxPath = request.getContextPath();
%>

<jsp:include page="header.jsp" />
<div class="container">
	<p class="h2 text-danger mt-4">장애발생</p>
    <img src="<%= ctxPath%>/images/error.gif" class="img-fluid" />
    <p class="h4 text-primary mt-3">빠른 복구를 위해 최선을 다하겠습니다</p>
</div>
<jsp:include page="footer.jsp" />

참고

0개의 댓글

관련 채용 정보