list

<%@ page language="java" contentType="text/html; charset=EUC-KR" %>
<%@ page import="java.util.*, java.sql.*" %>
<%
 request.setCharacterEncoding("EUC-KR");
 Connection con = null;
 Statement stmt = null;
 ResultSet rs = null;
 int listPerPage = 10; // 페이지에 출력할 리스트 개수

 /* JDBC driver loading 및 JDBC 접속 */
 try {
  Class.forName("org.gjt.mm.mysql.Driver");
  con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "jung", "asasas");
 } catch (ClassNotFoundException e) {
  out.println("Error:MySQL Connect Fail");
 }

 // 현재 페이지 수
 String pageString = request.getParameter("pages");
 int pageNum = 0;
 if (pageString==null || pageString.equals("")) {
  pageNum = 1;
 } else {
  pageNum = Integer.parseInt(pageString);
 }
 int startIdx = (pageNum - 1) * listPerPage;

 String searchField = request.getParameter("searchField");
 String searchText = request.getParameter("searchText");
 String queryReason = "";
 if (searchText==null || searchText.equals("")) {
  searchText = "";
  searchField = "";
  queryReason = "";
 } else {
  
  //searchText = new String(searchText.getBytes("8859_1"), "EUC-KR"); // 한글깨질때씀 한글되면 안씀
  queryReason = "where "+searchField+" like '%"+searchText+"%'";
 }
%>
<html>

<head>
 <title>오후 게시판 리스트</title>
 <style>
  body { font-size:9pt; color:#000000; line-height:13pt; text-decoration:none; }
  table { font-size:9pt; color:#000000; line-height:13pt; text-decoration:none; }
  td { font-size:9pt; color:#000000; line-height:13pt; text-decoration:none; }
  tr { font-size:9pt; color:#000000; line-height:13pt; text-decoration:none; }
  select { font-size:9pt; color:#000000; line-height:13pt; text-decoration:none; }
  input { font-size:9pt; color:#000000; line-height:13pt; text-decoration:none; }
  a:link { font-size:9pt; color:#000000; line-height:13pt; text-decoration:none; }
  a:hover { font-size:9pt; color:#000080; line-height:13pt; text-decoration:none; }
  a:active { font-size:9pt; color:#DDDDDD; line-height:13pt; text-decoration:none; }
  a:visited { font-size:9pt; color:#000000; line-height:13pt; text-decoration:none; } 
 </style>
</head>

<body>
 <center>
 <h1>오후 게시판 리스트</h1>
 <table border="0" cellpadding="0" cellspacing="0" width="600">
  <form name="search" method="get" action="list.jsp">
  <tr><td align="center">
   <select name="searchField">
    <option value="subject" <% if (searchField.equals("subject")) { out.println("selected"); } %>>제목</option>
    <option value="register" <% if (searchField.equals("register")) { out.println("selected"); } %>>등록자</option>
   </select>
   &nbsp;<input type="text" name="searchText" value="<%=searchText%>">
   &nbsp;<input type="submit" value="검색">
  </td></tr>
  </form>
 </table>
 <br>
 <table border="0" cellpadding="0" cellspacing="1" width="600">
  <tr bgcolor="#EEEEEE">
   <td width="30" align="center">순서</td>
   <td align="center">제목</td>
   <td width="80" align="center">등록자</td>
   <td width="80" align="center">등록일</td>
   <td width="40" align="center">조회수</td>
  </tr>
<%
 int recordCount = 0;
 try {
  stmt = con.createStatement();
  rs = stmt.executeQuery("select count(*) from board "+queryReason);
  if (rs.next()) {
   recordCount = rs.getInt(1);
  }
  if (recordCount==0) {
%>
  <tr><td colspan="5" align="center">등록된 게시물이 없습니다.</td></tr>
<%
  } else {
   rs = stmt.executeQuery("select subject, register, date_format(regist_date, '%Y/%m/%d'), hit, idx, re_deep,access_read from board "+queryReason+" order by re_idx desc,re_order asc,re_deep asc limit "+startIdx+", "+listPerPage);
   int lineCount = recordCount - startIdx;
   while (rs.next()) {
    String subject = rs.getString(1);
    String register = rs.getString(2);
    String registDate = rs.getString(3);
    int hit = rs.getInt(4);
    int idx = rs.getInt(5);
    int reDeep = rs.getInt(6);
    String access= rs.getString(7);
%>
  <tr onMouseOver="this.style.backgroundColor='#FFFFCC';" onMouseOut="this.style.backgroundColor='#FFFFFF';" onClick="<% if(access.equals("y")){%>JavaScript:document.location.href='content.jsp?idx=<%=idx%>&pages=<%=pageNum%>&searchField=<%=searchField%>&searchText=<%=searchText%>';<%}else{%>JavaScript:document.location.href='content_check1.jsp?idx=<%=idx%>&pages=<%=pageNum%>&searchField=<%=searchField%>&searchText=<%=searchText%>';<%}%>" style="cursor:hand;">
   <td align="center"><%=lineCount%></td>
   <td>
<%
    for (int i=0; i<reDeep; i++)
    {
   
     %><IMG SRC="./img/next.gif" WIDTH="13" HEIGHT="13" BORDER="0" ALT=""><%
    }
%>   
    &nbsp;
    <% if(access.equals("n")){%><IMG SRC="./img/key.gif" WIDTH="16" HEIGHT="16" ><%} %>
    <%=subject%>
   </td>
   <td align="center"><%=register%></td>
   <td align="center"><%=registDate%></td>
   <td align="center"><%=hit%></td>
  </tr>
  <tr><td colspan="5" height="1" bgcolor="#000000"></td></tr>
<%
    lineCount--;
   }
  }
 } catch (SQLException e) {
  System.out.println("Exception : "+e);
 } finally {
  try {
   if (rs!=null) { rs.close(); }
   if (stmt!=null) { stmt.close(); }
  } catch (SQLException e) {
   out.println("Exception : "+e);
  }
 }
%>
 </table>
 <table border="0" cellpadding="0" cellspacing="0" width="600">
  <tr><td align="center">
<%
  String listPage = "";
  String preIcon = "&lt;&lt;"; // 이전 page link로 넘길 때 icon
  String nextIcon = "&gt;&gt;"; // 다음 page link로 넘길 때 icon
  String pageLink = "searchField="+searchField+"&searchText="+searchText;
  int viewPage = 10; // 한 page에 출력할 page link 수

  /* 전체 page 수를 가져 옴 */
  int totalPage = 0;
  Float temp = new Float(recordCount/listPerPage);
  int temp_i = temp.intValue();

  if ((recordCount%listPerPage)==0) {
   totalPage = temp_i;
  } else {
   totalPage = temp_i + 1;
  }
  /* page link 값 계산 */
  Float pageList_f = new Float(((pageNum-1)/viewPage) * viewPage);
  int pageList = pageList_f.intValue();
  int viewPageList = pageList;
  /* 경우에 따른 출력 */
  if (pageList-viewPage>=0) { // 이전 viewPage개의 link가 있으면
   int previousPageCount = pageList;
   listPage = listPage + "<a href='list.jsp?pages=" + previousPageCount + "&" + pageLink + "'>" + preIcon + "</a>&nbsp;";
   listPage = listPage + "<a href='list.jsp?pages=1&" + pageLink + "'>1</a>&nbsp;...&nbsp;";
  } else {
   listPage = listPage + preIcon + "&nbsp;";
  }
  if (pageNum<=totalPage || totalPage==1) { // 중간 page link 출력
   while (viewPageList<pageList+viewPage && viewPageList<totalPage) {
    int displayCount = viewPageList + 1;
    listPage = listPage + "<a href='list.jsp?pages=" + displayCount + "&" + pageLink + "'>";
    if (viewPageList+1==pageNum) { listPage = listPage + "[" + displayCount + "]&nbsp;"; }
    else { listPage = listPage + displayCount + "&nbsp;"; }
    listPage = listPage + "</a>";
    viewPageList = viewPageList + 1;
   }
  } else {
   int pageStart = 0;
   int pageEnd = 0;
   if (pageNum-viewPage<=0) { pageStart = 1; pageEnd = totalPage; }
   else { pageStart = pageNum-viewPage; pageEnd = pageNum; }
   for (int i=pageStart; i<=pageEnd; i++) {
    listPage = listPage + "<a href='list.jsp?pages=" + i + "&" + pageLink + "'>";
    if (i==pageNum) { listPage = listPage + "["+ i + "]&nbsp;"; }
    else { listPage = listPage + i + "&nbsp;"; }
    listPage = listPage + "</a>";
   }
  }
  if ((pageList+viewPage+1)<=totalPage) { // 다음 viewPage개의 link가 있으면
   int nextPageCount = pageList + viewPage + 1;
   listPage = listPage + "...&nbsp;<a href='list.jsp?pages=" + totalPage + "&"+pageLink+"'>" + totalPage + "</a>&nbsp;";
   listPage = listPage + "<a href='list.jsp?pages=" + nextPageCount + "&" + pageLink + "'>" + nextIcon + "</a>";
  } else {
   listPage = listPage + nextIcon;
  }
  out.println(listPage);
%>
  </td></tr>
 </table>
 <table border="0" cellpadding="0" cellspacing="0" width="600">
  <tr><td height="5"></td></tr>
  <tr><td align="right">
   <input type="button" value="쓰기" onClick="JavaScript:document.location.href='writer.jsp';">
  </td></tr>  
 </table>
 </center>
</body>
<%
 con.close();
%>
</html>

by honam | 2008/06/04 13:47 | 트랙백 | 덧글(1)

트랙백 주소 : http://theurgistk.egloos.com/tb/4402082
☞ 내 이글루에 이 글과 관련된 글 쓰기 (트랙백 보내기) [도움말]
Commented by 1 at 2008/06/04 17:18
select subject, register, date_format(regist_date, '%Y/%m/%d'), hit, idx, re_deep from board "+queryReason+" order by re_idx desc, re_order asc limit "+startIdx+", "+listPerPage);

:         :

:

비공개 덧글

 

◀ 이전 페이지다음 페이지 ▶