<%@page import="java.util.Iterator"%>
<%@page import="endless.test.Board"%>
<%@page import="java.util.Vector"%>
<%@page import="endless.test.BoardDao"%>
<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<% request.setCharacterEncoding("euc-kr"); %>
<jsp:useBean id="list" class="endless.test.Board" />
<jsp:setProperty property="*" name="list"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>목록</title>
</head>
<body>
<%
int pageSize = 10; //한 화면에 보여질 페이지의 수입니다.
String pageNumber = request.getParameter("pageNumber");
if (pageNumber == null) {
pageNumber = "1";
}//만약에 페이지 수가 없다면 1이라는 숫자를 찍어라
int currentPage = Integer.parseInt(pageNumber);
int startRow = (currentPage - 1) * pageSize + 1;
int endRow = currentPage * pageSize;
int count = 0;
BoardDao dao = new BoardDao();
count = dao.getBoardCount();
dao.insert(list);
Vector<Board> boardlist = dao.getBoard(startRow, endRow);
Iterator<Board> i = boardlist.iterator();
%>
<table border="1">
<tr>
<td>번호</td>
<td>제목</td>
<td>글쓴이</td>
<td>등록일</td>
<td>조회</td>
</tr> <% while (i.hasNext()) { Board board = i.next(); %>
<tr>
<td><%=board.getWritenum()%></td>
<td><%=board.getTitle()%></td>
<td><%=board.getId()%></td>
<td><%=board.getWritedate()%></td>
<td><%=board.getHit() %></td>
</tr> <% } %>
<tr align="right">
<td colspan="5">
<%
if (count > 0) {
int pageCount = count / pageSize
+ (count % pageSize == 0 ? 0 : 1);
//페이지 숫자를 체크하기위해서.
//만약에 페이지의 숫자가 0일경우를 대비해서 한다.
int startPage = (int) ((currentPage - 1) / 10) * 10 + 1;
//처음페이지의 숫자
int pageBlock = 10; //페이지의숫자는 10
int endPage = startPage + pageBlock - 1;
if (endPage > pageCount)
endPage = pageCount;
if (startPage > 10) {
%><a href="list.jsp?pageNumber=<%=startPage - 10%>">[이전]</a>
<%
}
for (int pagecounter = startPage; pagecounter <= endPage; pagecounter++) {
%><a href="list.jsp?pageNumber=<%=pagecounter%>">[<%=pagecounter%>]</a>
<%
}
if (endPage < pageCount) {
%><a href="list.jsp?pageNumber=<%=startPage + 10%>">[다음]</a>
<%
}
}
%> <input type="submit" value="글쓰기">
</td>
</tr>
</table>
</body>
</html>