1. jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%@ page import="java.util.*" %>
<%@ page import="service.Svc" %>
<%@ page import="model.Object" %>
<%
String linkStr="";
int totcnt=18315; //토탈 게시물수
int pagecnt=10; //한페이지 표현 개시물수
int curpage=12; //현재 페이지
int pagelist=10; //페이징에 나타낼 번호 수
int pagetotlist = totcnt/pagecnt;
if(totcnt%pagecnt > 0) {
pagetotlist = pagetotlist+1;
}
if(request.getParameter("curpage") != null && !request.getParameter("curpage").equals("")) {
curpage = Integer.parseInt(request.getParameter("curpage"));
}
Svc ssSvc = new SubscribeSvc();
List aList = ssSvc.select(pagecnt,curpage);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<body>
<table>
<tr>
<td>순서</td>
<td>이름</td>
<td>메일</td>
</tr>
<%
for(int i=0; i<aList.size(); i++) {
Object ssObj = (Object)aList.get(i);
%>
<tr>
<td><%= ssObj.getIdx()%></td>
<td><%= ssObj.getName()%></td>
<td><%= ssObj.getEmail()%></td>
</tr>
<%
}
%>
</table>
<table>
<tr>
<td><a href="list.jsp?curpage=1">처음</a></td>
<%
for(int i=curpage-pagelist; i<=curpage+pagelist; i++) {
if(i == curpage) linkStr = "<font color='red'>"+i+"</font>";
else linkStr = String.valueOf(i);
if(i <= curpage && i > 0) {
if(curpage-i <= pagelist){
%>
<td><a href="list.jsp?curpage=<%= i%>"><%= linkStr%></a></td>
<%
}
else continue;
}
if(i > curpage && i<=pagetotlist) {
if(i-curpage <= pagelist){
%>
<td><a href="list.jsp?curpage=<%= i%>"><%= linkStr%></a></td>
<%
}
else continue;
}
}
%>
<td><a href="list.jsp?curpage=<%= pagetotlist%>">마지막</a></td>
</tr>
</table>
</body>
</html>
2. sql
sql.append(" select * ");
sql.append(" from (select a.*, rownum as rn, rownum as idx ");
sql.append(" from (select name, email ");
sql.append(" from table ");
sql.append(" order by name ) a ");
sql.append(" where rownum <= ?) ");
sql.append(" where rn > ? ");
pstmt.setInt(++i, (pagecnt*curpage));
pstmt.setInt(++i, (pagecnt*(curpage-1)));
'Java+Jsp' 카테고리의 다른 글
jsp ftp (Commons net) (0) | 2010.02.18 |
---|---|
jsp file upload (MultipartRequest ) (0) | 2010.02.18 |
java 디컴파일러 JAD, JADClipse (0) | 2009.11.13 |
xml 읽어오기 (0) | 2009.11.02 |
엑셀 저장하기 (0) | 2009.10.29 |