태터데스크 관리자

도움말
닫기
적용하기   첫페이지 만들기

태터데스크 메시지

저장하였습니다.

=========================== PagingTest.jsp ==================================

<html>
<head><title>페이징   블록 처리 테스트</title>
<link href="style.css" rel="stylesheet" type="text/css">
<body>
 <center>
  <br>
  <br>
  <h2>페이징   블록 처리 테스트</h2>
  <FORM METHOD=POST ACTION="PagingResult.jsp">
   총 레코드 값 : <INPUT TYPE="text" NAME="totalRecord">&nbsp;
      <INPUT TYPE="submit" value="보내기">
  </FORM>
 </center>
</body>
</html>

=========================== PagingResult.jsp ==================================

<%@ page contentType="text/html;charset=EUC-KR"%>
<%

 /*
  페이징에 필요한 변수 10가지
 
 // 초기값 변수 3개
 01. totalRecord  //전체 record 수 , 배열의 length, size(), length(), sql문의 count()
 02. NUM_PER_PAGE = 10; // 한 페이지에 보여질 행(목록)의 수 지정 , 상수
 03. PAGE_PER_BLOCK = 20; // 한 블록에서 보여질 페이지의 수 지정, 상수
 
 // 사용자 요청 변수 2개
 04. nowPage   //  디폴트 값은 1페이지(인덱스 값은 0), 사용자의 요청의 의해서 결정 ,
      //  request.getParameter("nowPage"); 으로 받아서 사용
      //  beginPerPage를 계산하는 데 사용하기 때문에 타입케스팅이 필요하다.
      //  Integer.parseInt(request.getParameter("nowPage"));
 05. nowBlock  //  디폴트 값은 1 블록(인덱스 값은 0), 사용자의 요청의 의해서 결정 ,
      // request.getParameter("nowBlock"); 으로 받아서 사용
      // 페이징의 페이지에 표시되는 숫자의 인덱스 값을 구하기 위해서 타입케스팅이 필요하다.
      //  Integer.parseInt(request.getParameter("nowBlock"));
 
 // 검색 처리 변수 2개
 06. keyField  // 검색기능을 수행 할 때 필요한 필드명를 저장하는 변수, sql문에서 사용
 07. keyWord   // 검색기능을 수행 할 때 필요한 필드의 검색하려는 내용을 저장하는 변수, sql문에서 사용
        // select * from board where " + keyField + " like '%" + keyWord + "%'
 
 // 페이징을 화면에 표시 할 때 필요한 변수 3개
 08. beginPerPage  // 페이지를 출력 할 때 첫번째 위치를 찾는 변수, for문의 초기값에 사용
                   // 계산하는 방법은  = (nowPage * NUM_PER_PAGE) + 1;
 09. totalPage   // 전체 페이지의 숫자를 저장해서 페이징의 페이지 숫자를 표시 할 때 필요,
          // 계산하는 방법은  = (totalREecord / NUM_PER_PAGE) + (((totalRecord % NUM_PER_PAGE) != 0) ? 1 : 0);
          // 계산하는 방법은  = (int)Math.ceil((double)totalRecord / NUM_PER_PAGE);
 10. totalBlock  // 전체 블록수를 저장해서 페이징의 블록 숫자를 표시 할 때 필요,
     // 계산하는 방법은  = (totalPage / NUM_PER_BLOCK) + (((totalRecord % NUM_PER_BLOCK) != 0) ? 1 : 0);
      // 계산하는 방법은  = (int)Math.ceil((double)totalPage / NUM_PER_BLOCK);
 */
 
    int nowPage = 0;
    int nowBlock = 0;
    int totalRecord = Integer.parseInt(request.getParameter("totalRecord"));
    int NUM_PER_PAGE = 7;          
    int PAGE_PER_BLOCK = 10;   
   
 int totalPage =(int)Math.ceil((double)totalRecord / NUM_PER_PAGE);
 int totalBlock =(int)Math.ceil((double)totalPage / PAGE_PER_BLOCK);
 
 if (request.getParameter("nowPage") != null){
   nowPage= Integer.parseInt(request.getParameter("nowPage")); }
 if (request.getParameter("nowBlock") != null){
   nowBlock = Integer.parseInt(request.getParameter("nowBlock"));}
 int beginPerPage =   nowPage * NUM_PER_PAGE; 
%>
<html>
<head><title>JSPBoard</title>
<link href="style.css" rel="stylesheet" type="text/css">
<script>
function preBlock(nowBlock,nowPage){
      document.total.nowBlock.value = nowBlock;
   document.total.nowPage.value = nowPage;
      total.submit();
 }

function prePage(nowBlock,nowPage){
      document.total.nowBlock.value = nowBlock;
   document.total.nowPage.value = nowPage;
      total.submit();
 }

function afterBlock(nowBlock,nowPage){
      document.total.nowBlock.value = nowBlock;
   document.total.nowPage.value = nowPage;
      total.submit();
 }
</script>
</head>
<body><center><br>
 <h2>페이징  블록 처리 테스트</h2>
 <br>
  <table>
   <tr>
   <td>게시물번호 : &nbsp;</td>
   </tr>
  
 <%
 for (int i = beginPerPage;i < (beginPerPage+NUM_PER_PAGE); i++) {
  if (i==totalRecord){ break;}
 %>
 <tr>
 <td align=center><%= i + 1  %>&nbsp;</td>
 </tr>
 <%}%>
 </table><p>
 <table>
  <tr>
   <td align="left" >
 <% if(totalRecord !=0){ %> Go to Page
 <% if (nowBlock > 0) {%>
 <a href="javascript:preBlock('<%=nowBlock - 1 %>','<%=((nowBlock - 1) * PAGE_PER_BLOCK)%>')">
 이전 <%=PAGE_PER_BLOCK %>개</a>
 <%}%>

 :::

 <%
    for (int i = 0; i < PAGE_PER_BLOCK; i++) { %>
    <a href="javascript:prePage('<%=nowBlock%>','<%=(nowBlock*PAGE_PER_BLOCK) + i %>')">
 <%=(nowBlock * PAGE_PER_BLOCK) + i + 1 %></a>
    <% if ((nowBlock * PAGE_PER_BLOCK) + i + 1 == totalPage) { break; } %>
 <%} %>

 :::

 <% if (totalBlock > nowBlock + 1) { %>
 <a href="javascript:afterBlock('<%=nowBlock + 1 %>','<%=((nowBlock +1) * PAGE_PER_BLOCK)%>')">
 다음 <%=PAGE_PER_BLOCK%>개</a>
 <%}%>

 <%} else{out.println("등록된 게시물이 없습니다."); }%>
    </td>
   </tr>
  </table>
  <form name="total">
   <input type="hidden" name ="totalRecord" value="<%=totalRecord%>">
   <input type="hidden" name ="nowBlock">
   <input type="hidden" name ="nowPage">
  </form>
  </center>
 </body>
</html>

top

Trackback Address :: http://www.ssial.com/trackback/149 관련글 쓰기

  1. asd 2011/11/13 21:47 댓글주소 | 수정/삭제 | 댓글

    asd

  2. abercrombie and fitch deutschland 2012/02/07 16:56 댓글주소 | 수정/삭제 | 댓글

    Keep up the good work!.

  3. abercrombie 2012/02/07 16:56 댓글주소 | 수정/삭제 | 댓글

    This was very informative. I have been reading your blog a lot over the past few days and it has earned a place in my bookmarks.

Write a comment


◀ PREV : [1] : ... [86] : [87] : [88] : [89] : [90] : [91] : [92] : [93] : [94] : ... [206] : NEXT ▶