-
2022-01-24 jsp 쇼핑몰 만들기#6학원/JSP SERVLET 2022. 1. 24. 16:13
2022-01-21 jsp 쇼핑몰 만들기 #5
https://omp14.tistory.com/82 주문하기 5) insertOrder(ArrayList list, String id) public int insertOrder(ArrayList list, String id) { int oseq = 0; con = Dbman.getConnection(); String sql = "insert in..
omp14.tistory.com
qna 작성
3) QnaWriteAction
public class QnaWriteAction implements Action { @Override public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String url = "shop.do?command=qnaList"; HttpSession session = request.getSession(); MemberVO mvo = (MemberVO) session.getAttribute("loginUser"); if(mvo == null) { url = "shop.do?command=loginForm"; } else { QnaVO qvo = new QnaVO(); qvo.setSubject(request.getParameter("subject")); qvo.setContent(request.getParameter("content")); qvo.setId(mvo.getId()); QnaDao qdao = QnaDao.getInstance(); qdao.insertQna(qvo); } response.sendRedirect(url); } }
4) insertQna(QnaVO qvo) 메소드
public void insertQna(QnaVO qvo) { String sql = "insert into qna(qseq, subject, content, id) values(qna_seq.nextval,?,?,?)"; con = Dbman.getConnection(); try { pstmt = con.prepareStatement(sql); pstmt.setString(1, qvo.getSubject()); pstmt.setString(2, qvo.getContent()); pstmt.setString(3, qvo.getId()); pstmt.executeUpdate(); } catch (SQLException e) {e.printStackTrace(); } finally { Dbman.close(con, pstmt, rs); } }
아이디 비밀번호 찾기
1) member/login.jsp -> 아이디 비밀번호 찾기 버튼을 누르면 find_account() 함수가 실행됨
function find_account(){ var url="shop.do?command=findAccount"; var opt = "toolbar=no, menubar=no, resizable=no, width=700, height=500, top=300, left=300"; window.open(url, "Find Id/Pw", opt); }
팝업창을 열어주는 함수
2) FindAccountAction
public class FindAccountAction implements Action { @Override public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String url = "member/findAccount.jsp"; request.getRequestDispatcher(url).forward(request, response); } }
3) member/findAccount.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <link href="css/shopping.css" rel="stylesheet"> </head> <body> <center><h3>아이디 / 비밀번호 찾기</h3></center> <form> <table align="center" bgcolor="black" cellspacing="1" width="400"> <tr align="center" bgcolor="#fde8ff" height="200"> <td width="230"><h4>아이디 찾기</h4><br> <input type="button" class="submit" value="이동" onclick="location.href='shop.do?command=findIdForm'"> </td> <td width="230"><h4>비밀번호 찾기</h4><br> <input type="button" class="submit" value="이동" onclick="location.href='shop.do?command=findPwForm'"> </td> </tr> </table> </form> </body> </html>
4) FindIdFormAction
public class FindIdFormAction implements Action { @Override public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String url ="member/findIdForm.jsp"; request.getRequestDispatcher(url).forward(request, response); } }
5) member/findIdForm.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <link href="css/shopping.css" rel="stylesheet"> </head> <body> <center><h2>Id 찾기</h2></center> <form method="post" name="frm" action="shop.do"> <input type="hidden" name="command" value="findIdStep1"> <table align="center" bgcolor="black" cellspacing="1" width="400"> <tr align="center" bgcolor="#fde8ff"> <td width=430><h3>성명 <input type="text" name="name" value="${name}"></h3></td> <!-- 인증번호가 일치 하지 않아 이 화면으로 돌아올 때는 parameter에 name, phone을 가지고 오게 하여 이미 입력한 name과 phone을 다시 입력하지 않아도 되도록 함 --> </tr> <tr align="center"="center" bgcolor="#fde8ff"> <td width=430><h3>전화번호 <input type="text" name="phone" value="${phone}"></h3></td> </tr> <tr align="center" bgcolor="#fde8ff"> <td width=430><h3><input type="submit"value="인증번호 전송"></h3> ${msg} </td> </tr> </table> </form> </body> </html>
6) FindIdStep1Action
public class FindIdStep1Action implements Action { @Override public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String name = request.getParameter("name"); String phone = request.getParameter("phone"); String url = "member/findIdForm.jsp"; MemberDao mdao = MemberDao.getInstance(); MemberVO mvo = mdao.getMemberByName(name, phone); request.setAttribute("name", name); request.setAttribute("phone", phone); if(mvo == null) { //해당 이름이 없음 request.setAttribute("msg", "해당하는 이름의 회원이 없습니다."); } else { request.setAttribute("memberVO", mvo); url = "member/findIdconfirmNumber.jsp"; } request.getRequestDispatcher(url).forward(request, response); } }
7) getMemberByName(String name, String phone)
public MemberVO getMemberByName(String name, String phone) { MemberVO mvo = null; String sql="select * from member where name=? and phone=?"; con = Dbman.getConnection(); try { pstmt = con.prepareStatement(sql); pstmt.setString(1, name); pstmt.setString(2, phone); rs = pstmt.executeQuery(); if(rs.next()) { mvo = new MemberVO(); mvo.setId(rs.getString("id")); mvo.setName(rs.getString("name")); mvo.setPhone(rs.getString("phone")); } } catch (SQLException e) {e.printStackTrace(); } finally { Dbman.close(con, pstmt, rs); } return mvo; }
8) findIdconfirmNumber.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <link href="css/shopping.css" rel="stylesheet"> </head> <body> <h2>Id 찾기</h2> <form method="post" name="frm" action="shop.do"> <input type="hidden" name="command" value="findIdStep2"> <table align="center" bgcolor="black" cellspacing="1" width="400"> <tr align="center" bgcolor="#fde8ff"> <td width="430"><h3>성명 : ${name}</h3> <input type="hidden" name="name" value="${name}"></td></tr> <tr align="center" bgcolor="#fde8ff"> <td width="430"><h3>전화번호 : ${phone}</h3> <input type="hidden" name="phone" value="${phone}"> <input type="hidden" name="id" value="${MemberVO.id}"></td></tr> <tr align="center" bgcolor="#fde8ff"> <td width="430"><h3>인증번호 <input type="text" name="confirmNum"></h3> 전송받은 번호를 입력하세요<br> ${msg}<br><input type="submit" value="인증번호 확인"></td></tr> </table> </form> </body> </html>
9) FindIdStep2Action
인증번호는 그냥 0000으로 고정....
public class FindIdStep2Action implements Action { @Override public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String confirmNum = request.getParameter("confirmNum"); MemberVO mvo = new MemberVO(); mvo.setId(request.getParameter("id")); mvo.setName(request.getParameter("name")); mvo.setPhone(request.getParameter("phone")); request.setAttribute("name", mvo.getName()); request.setAttribute("phone", mvo.getPhone()); request.setAttribute("id", mvo.getId()); request.setAttribute("MemberVO", mvo); String url ="member/viewId.jsp"; if(!confirmNum.equals("0000")) { request.setAttribute("msg", "인증번호가 일치하지 않습니다."); url = "member/findIdconfirmNumber.jsp"; } request.getRequestDispatcher(url).forward(request, response); } }
10) viewId.jsp
11) FindPwFormAction 비밀번호 찾기
-아이디찾기와 거의 유사,,
public class FindPwFormAction implements Action { @Override public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String url ="member/findPwForm.jsp"; request.setAttribute("id", request.getParameter("id")); request.getRequestDispatcher(url).forward(request, response); } }
11) findPwForm.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <link href="css/shopping.css" rel="stylesheet"> </head> <body> <center><h2>비밀번호 찾기</h2></center> <form method="post" name="frm" action="shop.do"> <input type="hidden" name="command" value="findPwStep1"> <table align="center" bgcolor="black" cellspacing="1" width="400"> <tr align="center" bgcolor="#fde8ff"> <td width=430><h3>아이디 <input type="text" name="id" value="${id}"></h3></td> </tr> <tr align="center" bgcolor="#fde8ff"> <td width=430><h3>성명 <input type="text" name="name" value="${name}"></h3></td> </tr> <tr align="center" bgcolor="#fde8ff"> <td width=430><h3>전화번호 <input type="text" name="phone" value="${phone}"></h3></td> </tr> <tr align="center" bgcolor="#fde8ff"> <td width=430><h3><input type="submit"value="인증번호 전송"></h3> ${msg} </td> </tr> </table> </form> </body> </html>
12)FindPwStep1
public class FindPwStep1Action implements Action { @Override public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String id = request.getParameter("id"); String name = request.getParameter("name"); String phone = request.getParameter("phone"); String url = "member/findPwForm.jsp"; MemberDao mdao = MemberDao.getInstance(); MemberVO mvo = mdao.getMember(id); if(mvo == null) { request.setAttribute("msg", "일치하는 회원이 존재하지 않습니다."); } else if( (!name.equals(mvo.getName())) || (!phone.equals(mvo.getPhone())) ) { request.setAttribute("msg", "id와 회원 정보가 일치하지 않습니다."); } else { request.setAttribute("member", mvo); url = "member/findPwconfirmNumber.jsp"; } request.getRequestDispatcher(url).forward(request, response); } }
13) findPwconfirmNumber.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <link href="css/shopping.css" rel="stylesheet"> </head> <body> <center><h2>비밀번호 찾기</h2></center> <form method="post" name="frm" action="shop.do"> <input type="hidden" name="command" value="findPwStep2"> <table align="center" bgcolor="black" cellspacing="1" width="400"> <tr align="center" bgcolor="#fde8ff"> <td width="430"><h3>아이디 : ${member.id}</h3> <input type="hidden" name="id" value="${member.id}"></td></tr> <tr align="center" bgcolor="#fde8ff"> <td width="430"><h3>성명 : ${member.name}</h3> <input type="hidden" name="name" value="${member.name}"></td></tr> <tr align="center" bgcolor="#fde8ff"> <td width="430"><h3>전화번호 : ${member.phone}</h3> <input type="hidden" name="phone" value="${member.phone}"> <tr align="center" bgcolor="#fde8ff"> <td width="430"><h3>인증번호 <input type="text" name="confirmNum"></h3> 전송받은 번호를 입력하세요<br> ${msg}<br><input type="submit" value="인증번호 확인"></td></tr> </table> </form> </body> </html>
14) FindPwSteo2Action
public class FindPwStep2Action implements Action { @Override public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String confirmNum = request.getParameter("confirmNum"); String id = request.getParameter("id"); String name = request.getParameter("name"); String phone = request.getParameter("phone"); request.setAttribute("id", id); request.setAttribute("name", name); request.setAttribute("phone", phone); String url = "member/findPwconfirmNumber.jsp"; if(confirmNum.equals("0000")) url="member/resetPw.jsp"; request.getRequestDispatcher(url).forward(request, response); } }
15) resetPw.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <link href="css/shopping.css" rel="stylesheet"> <script type="text/javascript"> function resetPw(){ if(document.frm.pwd.value==""){ alert("비밀번호를 입력하세요"); documet.frm.pwd.focus(); return false(); } if(document.frm.pwd.value!==document.frm.pwd_chk.value){ alert("비밀번호와 비밀번호 확인이 일치하지 않습니다."); documet.frm.pwd.focus(); return false(); } return true; } </script> </head> <body> <center><h2>비밀번호 재설정</h2></center> <form method="post" name="frm" action="shop.do"> <input type="hidden" name="command" value="resetPw"> <input type="hidden" name="id" value="${id}"> <table align="center" bgcolor="black" cellspacing="1" width="400"> <tr align="center" bgcolor="#fde8ff"> <td width="430"><h3>비밀번호 <input type="password" name="pwd"></h3></td> </tr> <tr align="center" bgcolor="#fde8ff"> <td width="430"><h3>비밀번호 확인<input type="password" name="pwd_chk"></h3></td> </tr> <tr align="center" bgcolor="#fde8ff"> <td width="430"><h3><input type="submit" value="비밀번호 재설정" onClick="return resetPw();"></h3></td> </tr> </table> </form> </body> </html>
16) ResetPwAction
package com.ac.controller.action; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.ac.dao.MemberDao; import com.ac.dto.MemberVO; public class ResetPwAction implements Action { @Override public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { MemberVO mvo = new MemberVO(); mvo.setId(request.getParameter("id")); mvo.setPwd(request.getParameter("pwd")); MemberDao mado = MemberDao.getInstance(); mado.resetPw(mvo); String url="member/resetPwComplete.jsp"; request.getRequestDispatcher(url).forward(request, response); } }
17) resetPw(MemberVO mvo) 메소드
public void resetPw(MemberVO mvo) { String sql = "update member set pwd=? where id=?"; con = Dbman.getConnection(); try { pstmt = con.prepareStatement(sql); pstmt.setString(1, mvo.getPwd()); pstmt.setString(2, mvo.getId()); pstmt.executeUpdate(); } catch (SQLException e) {e.printStackTrace(); } finally { Dbman.close(con, pstmt, rs); } }
18) resetPwComplete.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <link href="css/shopping.css" rel="stylesheet"> <script type="text/javascript"> function move_login(){ opener.location.href='shop.do?command=loginForm'; self.close(); } </script> </head> <body> <h2>비밀번호 재설정 완료</h2> <table align="center" bgcolor="black" cellspacing="1" width="400"> <tr align="center" bgcolor="#fde8ff" height="200"> <td width="230"><h3>비밀번호 재설정이 완료되었습니다</h3><br> <input type="button" vlaue="로그인 페이지로" onClick="move_login();"> </td> </tr> </body> </html>
관리자 페이지
1) actionFactory에 else if 문 command = admin 추가
-관리자 메뉴만 따로 관리하기 위해 com.ac.controller.admin.action 경로에 AdminAction 클래스 추가
-http://localhost:8090/WEB12_Shoppingmall/shop.do?command=admin을 직접 입력하여 접근하도록 함
public class AdminAction implements Action { @Override public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String url = "admin/adminLogin.jsp"; request.getRequestDispatcher(url).forward(request, response); } }
관리자 로그인창으로 이동
2) WebContent에 admin 폴더 만들고 adminLogin.jsp 생성
- css파일과 images 도 준비
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> <link rel="stylesheet" href="admin/css/admin.css"> <script type="text/javascript"> function workerCheck(){ if(docunment.frm.workId.value==""){ alert("아이디를 입력해주세요.") return false; } if(docunment.frm.workPwd.value==""){ alert("비밀번호를 입력해주세요.") return false; } return true; } </script> </head> <body> <div id="wrap"> <header> <div id="logo"> <img src="admin/images/bar_01.gif" style="float:left;"> <img src="admin/images/text.gif"> </div> </header> <article> <div id="loginform"> <form name="frm" method="post" action="shop.do"> <input type="hidden" name="command" value="adminLogin"> <table> <tr> <td>아 이 디</td> <td><input type="text" name="workId" size="10"></td> </tr> <tr> <td>비밀번호</td> <td><input type="password" name="workPwd" size="10"></td> </tr> <tr align="center"> <td colspan="2"><input class="btn" type="submit" value="로그인" onClick="return workerCheck();"> <br><br><h4 style="color:red">${message}</h4></td> </tr> </table> </form> </div> </article> </div> </body> </html>
메인 페이지에서 command=admin으로 변경하면 위와 같이 관리자 화면 진입 3) AdminDao : 싱글턴 + 전역변수 생성
4) AdminVO
public class AdminVO { private String id; private String pwd; private String name; private String phone; //이하 getter,setter }
5) AdminLoginAction
public class AdminLoginaction implements Action { @Override public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String workId = request.getParameter("workId"); String workPwd = request.getParameter("workPwd"); String url = "shop.do?command=admin"; AdminDao adao = AdminDao.getInstance(); AdminVO avo = adao.workerCheck(workId); //String pwd = adao.workerCheck(workId); //AdminVO는 로그인 할 때를 제외하고는 사용하지 않으므로 dto를 생성하지않고 //String 변수로 처리해도 무방 if(avo==null) request.setAttribute("msg", "존재하지 않는 관리자 아이디 입니다."); else if(avo.getPwd() == null) request.setAttribute("msg", "DB오류. 관리자에게 문의하세요."); else if(!avo.getPwd().equals(workPwd)) request.setAttribute("msg", "비밀번호가 일치하지 않습니다"); else { HttpSession session = request.getSession(); session.setAttribute("loginAdmin", avo); url = "shop.do?command=adminProductList"; } request.getRequestDispatcher(url).forward(request, response); } }
6) wokerCheck(String workId) 메소드
public ArrayList<ProductVO> listProduct() { ArrayList<ProductVO> list = new ArrayList<>(); String sql = "select * from product order by pseq desc"; con = Dbman.getConnection(); try { pstmt = con.prepareStatement(sql); rs = pstmt.executeQuery(); while(rs.next()) { ProductVO pvo = new ProductVO(); pvo.setContent(rs.getString("content")); pvo.setPseq(rs.getInt("pseq")); pvo.setIndate(rs.getTimestamp("indate")); pvo.setName(rs.getString("name")); pvo.setPrice1(rs.getInt("price1")); pvo.setPrice2(rs.getInt("price2")); pvo.setPrice3(rs.getInt("price3")); pvo.setImage(rs.getString("image")); pvo.setBestyn(rs.getString("bestyn")); pvo.setUseyn(rs.getString("useyn")); list.add(pvo); } } catch (SQLException e) { e.printStackTrace(); } finally { Dbman.close(con, pstmt, rs); } return list; }
7) header.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> <meta charset="UTF-8"> <title>Insert title here</title> <link rel="stylesheet" href="admin/css/admin.css"> <script src="admin/product/product.js"></script> </head> <body> <div id="wrap"> <header> <div id="logo"> <img style="width:800px" src="admin/images/bar_01.gif"> <img src="admin/images/text.gif"> </div> <input class="btn" type="button" value="logout" style="float:right" onclick="location.href='shop.do?command=adminLogout'"> </header> <div class="clear"></div>
8) sub_menu.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <meta charset="UTF-8"> <nav id="sub_menu"> <h1>관리자 설정</h1> <ul> <li><a href='shop.do?command=adminProductList'>상품리스트</a></li> <li><a href='shop.do?command=adminOrderList'>주문리스트</a></li> <li><a href='shop.do?command=adminMemberList'>회원리스트</a></li> <li><a href='shop.do?command=adminQnaList'>Q&A리스트</a></li> </ul> </nav>
9) footer.jsp
<div class="clear"></div> <footer> <hr> <div id="copy"> All contents Copyright 2022 HJKang.co Inc. all rights reserved <br> Contact mail : abc@abc.com Tel : +82 02 1234 1234 </div> </footer> </div> <!-- wrap div가 여기서 끝 --> </body> </html>
10) admin/product/productList.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ include file="/admin/header.jsp" %> <%@ include file="/admin/sub_menu.jsp" %> <article> <h1>상품 리스트</h1> <form name="frm" method="post"> <tr> <td width="642"> 상품명 <input type="text" name="key" value="${key}"> <input class="btn" type="button" name="btn_serach" value="검색" onClick="go_search();"> <input class="btn" type="button" name="btn_total" value="전체보기" onClick="go_total();"> <input class="btn" type="button" name="btn_write" value="상품 등록" onClick="go_wrt();"> </td> </tr> </form> <table id="productList" > <tr> <th>번호</th> <th>상품명</th> <th>사입가</th> <th>판매가</th> <th>등록일</th> <th>사용유무</th> </tr> <c:forEach items="${productList}" var="productVO"> <tr> <td height="23" align="center"> ${productVO.pseq}</td> <td style="text-align:left; padding-left:50px;"> <a href="#" onClick="go_detail('${productVO.pseq}');">${productVO.name}</a> </td> <td><fmt:formatNumber value="${productVO.price1}"/></td> <td><fmt:formatNumber value="${productVO.price2}"/></td> <td><fmt:formatDate value="${productVO.indate}"/></td> <td><c:choose> <c:when test='${productVO.useyn=="n"}'>미사용</c:when> <c:otherwise>사용</c:otherwise> </c:choose> </c:forEach> </table> <div id="paging" align="center" style="font-size:110%; font-wight:bold;"> <c:url var="action" value="shop.do?command=adminProductList"/> <c:if test="${paging.prev}"> <a href="${action}&page=${paging.beginPage-1}">◀</a> </c:if> <c:forEach begin="${paging.beginPage}" end="${paging.endPage}" var="index"> <c:choose> <c:when test="${paging.page==index}"> <span style="color:red">${index} </span> </c:when> <c:otherwise> <a href="${action}&page=${index}">${index}</a> </c:otherwise> </c:choose> </c:forEach> <c:if test="${paging.next}"> <a href="${action}&page=${paging.endPage+1}">▶</a> </c:if> </div> </article> <%@ include file="/admin/footer.jsp" %>
11) 페이징 작업을 위해 샘플 데이터를 100개가 넘도록 추가
12) Paging.java
package com.ac.util; public class Paging { private int page = 1; private int totalCount; private int displayRow = 10; private int displayPage = 10; private int beginPage; private int endPage; private boolean prev; private boolean next; private int startNum; private int endNum; private void paging() { endPage = ((int)Math.ceil(page/(double)displayPage))* displayPage; beginPage = endPage-(displayPage-1); int totalPage = (int)Math.ceil(totalCount/(double)displayRow); if(totalPage<endPage) { endPage = totalPage; next = false; } else { next = true; } prev = (beginPage ==1)?false:true; startNum = (page-1)*displayRow+1; endNum = page*displayRow; System.out.println(beginPage+" " + endPage + " " + startNum + " " + endNum + " " + totalCount); //나중에 지울것 } public int getPage() { return page; } public void setPage(int page) { this.page = page; } public int getTotalCount() { return totalCount; } public void setTotalCount(int totalCount) { this.totalCount = totalCount; paging(); } public int getDisplayRow() { return displayRow; } //이하 생략 }
setTotalCount가 호출되면 자동으로 paging 메소드가 호출 이외에는 그냥 getter/setter
13)AdminProductListAction
public class AdminProductListAction implements Action { @Override public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String url = "admin/product/productList.jsp"; HttpSession session = request.getSession(); AdminVO avo = (AdminVO) session.getAttribute("loginAdmin"); if(avo==null) url = "shop.do?command=admin"; else { int page = 1; if(request.getParameter("page") != null) page = Integer.parseInt(request.getParameter("page")); Paging paging = new Paging(); paging.setPage(page); AdminDao adao = AdminDao.getInstance(); int count = adao.getAllCount(); //총게시물 수 얻어오기 paging.setTotalCount(count); //실행 시 paging() 메소드도 함께 실행됨 request.setAttribute("paging", paging); ArrayList<ProductVO> productList = adao.listProduct(paging); request.setAttribute("productList", productList); } request.getRequestDispatcher(url).forward(request, response); } }
페이징까지 끝
'학원 > JSP SERVLET' 카테고리의 다른 글
2022-01-26 jsp 쇼핑몰 만들기 #8 (0) 2022.01.26 2022-01-25 jsp 쇼핑몰 만들기 #7 (0) 2022.01.25 2022-01-21 jsp 쇼핑몰 만들기 #5 (0) 2022.01.21 2022-01-20 jsp 쇼핑몰 만들기 #4 (0) 2022.01.20 2022-01-19 jsp 쇼핑몰 만들기 #3 (0) 2022.01.19