note

갤러리 게시판 프로그램 본문

JSP/기본

갤러리 게시판 프로그램

투한 2012. 2. 17. 17:47







예제



<%@ 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 PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>게시판</title>
<script type="text/javascript">
  function searchMessage(){
   if(document.search.keyWord.value==""){
     alert("검색어를 입력하세요");
     document.search.keyWord.focus();
     return false;
   }
   return true;
  }
</script>
</head>

<body>
<center>
 <form action="list.do" name="search" method="get" onsubmit="return searchMessage()">
<table width="200" border="0" align="center" cellpadding="4" cellspacing="0">
  <tr>
    <td align="center" valign="bottom">
      <select name="keyField">
      	<option value="subject">제목</option>      
      	<option value="writer">이름</option>
      	<option value="content">내용</option>
      </select>
    </td>
    <td>
    	<input type="text" size=16 name="keyWord">
    </td>
    <td>
     <input type="submit" value="찾기"></td>
   </tr> 
</table>
</form>
<table width="700" cellpadding="0" cellspacing="0">
<tr>
    <td><b>전체 글:${page.count}</b></td>
    <td align="right">
    <a href="writeForm.do">글쓰기</a>
    </td>
</tr>    
</table>
<c:if test="${page.count == 0}">
<table width="700" border="1" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center">
      게시판에 저장된 글이 없습니다.
    </td>
  </tr>
</table>
</c:if>

<c:if test="${page.count > 0}">
<table border="1" width="700" cellpadding="0" cellspacing="0" align="center"> 
    <tr height="30"> 
      <td align="center"  width="50"  >번 호</td> 
      <td align="center"  width="250" >제   목</td> 
      <td align="center"  width="100" >작성자</td>
      <td align="center"  width="150" >작성일</td> 
      <td align="center"  width="50" >조 회</td> 
      <td align="center"  width="100" >IP</td>    
    </tr>
    
   <c:set var="number" value="${page.number}"/>
   <c:forEach var="article" items="${articleList}">
   <tr height="30">
    <td align="center"  width="50" >
	  ${number}
	  <c:set var="number" value="${number - 1}"/>
	</td>
    <td  width="250" >
    <c:if test="${! empty article.image}">
    <img src="/album/upload/${article.image}" 
    width="70" height="70" border="0">
    </c:if>
      <a href="content.do?num=${article.num}">
          ${article.subject}</a> 
	</td>
    <td align="center"  width="100"> 
       ${article.writer}
	</td>
    <td align="center"  width="150">${article.reg_date}
	</td>
    <td align="center"  width="50">${article.readcount}</td>
    <td align="center" width="100" >${article.ip}</td>
  </tr>
  </c:forEach>
</table>
</c:if>

<c:if test="${page.count > 0}">
   <c:set var="pageCount" value="${(page.count - 1) / page.pageSize + 1}"/>
   <c:set var="pageBlock" value="${10}"/>
   <fmt:parseNumber var="rs" value="${(currentPage - 1) / pageBlock}" integerOnly="true" />
   <c:set var="startPage" value="${rs*pageBlock+1}"/>
   <c:set var="endPage" value="${startPage + pageBlock-1}"/>
   <c:if test="${endPage > pageCount}">
        <c:set var="endPage" value="${pageCount}"/>
   </c:if> 
          
   <c:if test="${startPage > pageBlock}">
        <a href="list.do?pageNum=${startPage - pageBlock }&keyField=${page.keyField}&keyWord=${page.keyWord}">[이전]</a>
   </c:if>

   <c:forEach var="i" begin="${startPage}" end="${endPage}">
       <c:if test="${i == page.currentPage}">
          [${i}]
       </c:if>
       <c:if test="${i != page.currentPage}">
           <a href="list.do?pageNum=${i}&keyField=${page.keyField}&keyWord=${page.keyWord}">[${i}]</a>
       </c:if>
   </c:forEach>

   <c:if test="${endPage < pageCount}">
        <a href="list.do?pageNum=${startPage + pageBlock}&keyField=${page.keyField}&keyWord=${page.keyWord}">[다음]</a>
   </c:if>
</c:if>

</center>
</body>
</html>