Web/게시판2012. 8. 23. 23:44



결과화면이다.

급하게 만든 게시판이다. 쓰기와 로그인 리스트와 페이징만 되는 게시판이다.

게시판의 기능으로 읽기도 있을것이며 삭제, 수정, 답글달기 댓글달기는

MVC패턴의 게시판을 하면서 하겠습니다.

'Web > 게시판' 카테고리의 다른 글

list.jsp 최종  (0) 2012.08.23
BoardDao 최종  (0) 2012.08.23
BoardDao 추가  (0) 2012.08.23
페이징 할때 쿼리  (0) 2012.08.21
전체글 갯수 구하기  (0) 2012.08.20
Posted by NeverTry
Web/게시판2012. 8. 23. 23:39

list.jsp파일 내용


<%@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>

'Web > 게시판' 카테고리의 다른 글

결과화면  (0) 2012.08.23
BoardDao 최종  (0) 2012.08.23
BoardDao 추가  (0) 2012.08.23
페이징 할때 쿼리  (0) 2012.08.21
전체글 갯수 구하기  (0) 2012.08.20
Posted by NeverTry
Web/게시판2012. 8. 23. 23:34
package endless.test;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

public class BoardDao {
	Board board;
	Connection connection;
	PreparedStatement preparedStatement;
	DataBaseChoice dbchoice = new DataBaseChoice();
	Vector boardlist;
	ResultSet resultset;

	public void insert(Object object) throws SQLException,
			ClassNotFoundException {
		board = (Board) object;
		connection = dbchoice.makeConnection();
		String insertQuery = "INSERT INTO BOARD (id,title,content,hit,writedate) VALUES (?,?,?,0,now())";
		preparedStatement = connection.prepareStatement(insertQuery);
		preparedStatement.setString(1, board.getId());
		preparedStatement.setString(2, board.getTitle());
		preparedStatement.setString(3, board.getContent());
		preparedStatement.executeUpdate();

		preparedStatement.close();
		connection.close();

	}

	public int getBoardCount() throws SQLException, ClassNotFoundException {
		int value = 0;
		connection = dbchoice.makeConnection();
		String countQuery = "SELECT COUNT(*) FROM BOARD";
		preparedStatement = connection.prepareStatement(countQuery);
		resultset = preparedStatement.executeQuery();

		if (resultset.next()) {
			value = resultset.getInt(1);
		}
		return value;
	}

	public Vector getBoard(int startRow, int endRow)
			throws SQLException, ClassNotFoundException {
		boardlist = new Vector();

		connection = dbchoice.makeConnection();
		String pagingQuery = "SELECT * FROM (SELECT @ROWNUM :=@ROWNUM +1 AS ROW, A.* FROM (SELECT * FROM BOARD ORDER BY WRITENUM DESC) A, (SELECT @ROWNUM := 0) B) C WHERE C.ROW BETWEEN ? AND ?";
		preparedStatement = connection.prepareStatement(pagingQuery);
		preparedStatement.setInt(1, startRow);
		preparedStatement.setInt(2, endRow);

		resultset = preparedStatement.executeQuery();

		while (resultset.next()) {
			board = new Board();

			board.setWritenum(resultset.getInt("writenum"));
			board.setId(resultset.getString("id"));
			board.setTitle(resultset.getString("title"));
			board.setContent(resultset.getString("content"));
			board.setHit(resultset.getInt("hit"));
			board.setWritedate(resultset.getTimestamp("writedate"));

			boardlist.add(board);
		}

		preparedStatement.close();
		connection.close();

		return boardlist;

	}

}

'Web > 게시판' 카테고리의 다른 글

결과화면  (0) 2012.08.23
list.jsp 최종  (0) 2012.08.23
BoardDao 추가  (0) 2012.08.23
페이징 할때 쿼리  (0) 2012.08.21
전체글 갯수 구하기  (0) 2012.08.20
Posted by NeverTry