'Web/게시판'에 해당되는 글 21건

  1. 2012.08.23 결과화면
  2. 2012.08.23 list.jsp 최종
  3. 2012.08.23 BoardDao 최종
  4. 2012.08.23 BoardDao 추가
  5. 2012.08.21 페이징 할때 쿼리
  6. 2012.08.20 전체글 갯수 구하기
  7. 2012.08.19 list.jsp 및 결과
  8. 2012.08.19 BoardDao 추가
  9. 2012.08.19 BoardDao
  10. 2012.08.19 write.jsp
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
Web/게시판2012. 8. 23. 23:13



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

list.jsp 최종  (0) 2012.08.23
BoardDao 최종  (0) 2012.08.23
페이징 할때 쿼리  (0) 2012.08.21
전체글 갯수 구하기  (0) 2012.08.20
list.jsp 및 결과  (0) 2012.08.19
Posted by NeverTry
Web/게시판2012. 8. 21. 22:49

교육센터에서 배울땐 오라클로 했었는데


Oracle 에서 페이징 할때 쿼리

select * from 

(select rownum rm, board.* from 

(select * from article order by writenum desc) board) 

where rm between ? and ?


Mysql 에서 페이징 할때 쿼리

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 ?


쿼리 추가 insert

INSERT INTO BOARD (id,title,content,hit,writedate) VALUES ('taehun','four','test1',0,now());

INSERT INTO BOARD (id,title,content,hit,writedate) VALUES ('taehun','five','test2',0,now());

INSERT INTO BOARD (id,title,content,hit,writedate) VALUES ('taehun','six','test3',0,now());

INSERT INTO BOARD (id,title,content,hit,writedate) VALUES ('taehun','seven','test4',0,now());

INSERT INTO BOARD (id,title,content,hit,writedate) VALUES ('taehun','eight','test5',0,now());

INSERT INTO BOARD (id,title,content,hit,writedate) VALUES ('taehun','nine','test6',0,now());

INSERT INTO BOARD (id,title,content,hit,writedate) VALUES ('taehun','ten','test7',0,now());

INSERT INTO BOARD (id,title,content,hit,writedate) VALUES ('taehun','eleven','test8',0,now());





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

BoardDao 최종  (0) 2012.08.23
BoardDao 추가  (0) 2012.08.23
전체글 갯수 구하기  (0) 2012.08.20
list.jsp 및 결과  (0) 2012.08.19
BoardDao 추가  (0) 2012.08.19
Posted by NeverTry
Web/게시판2012. 8. 20. 23:06



BoardDao.java

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 Vector list() throws ClassNotFoundException, SQLException{
		boardlist = new Vector();
		
			connection = dbchoice.makeConnection();
			String query = "SELECT * FROM BOARD";
			preparedStatement = connection.prepareStatement(query);
			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;
	}
	
	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;
	}
	
}


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

BoardDao 추가  (0) 2012.08.23
페이징 할때 쿼리  (0) 2012.08.21
list.jsp 및 결과  (0) 2012.08.19
BoardDao 추가  (0) 2012.08.19
BoardDao  (0) 2012.08.19
Posted by NeverTry
Web/게시판2012. 8. 19. 15:32



결과 화면




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

페이징 할때 쿼리  (0) 2012.08.21
전체글 갯수 구하기  (0) 2012.08.20
BoardDao 추가  (0) 2012.08.19
BoardDao  (0) 2012.08.19
write.jsp  (0) 2012.08.19
Posted by NeverTry
Web/게시판2012. 8. 19. 11:20

글을 썼다면 간단한 내용으로 게시판의 화면에 보여질 글을 읽어와야한다.

즉. 글번호라든지 글제목 글쓴이 등 이 부분을 게시판에 보여줘야한다.

이부분을 BoardDao에 추가한다.

추가된 메소드



완성된 BoardDao

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){
		board = (Board) object;
		try{
		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();
		
		}catch(SQLException e){
			e.printStackTrace();
		}catch(ClassNotFoundException cnfe){
			cnfe.printStackTrace();
		}
		
	}
	
	public Vector list(){
		boardlist = new Vector();
		
		try {
			connection = dbchoice.makeConnection();
			String query = "SELECT * FROM BOARD";
			preparedStatement = connection.prepareStatement(query);
			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();
			
		} catch (SQLException e) {
			e.printStackTrace();
		}catch(ClassNotFoundException cnfe){
			cnfe.printStackTrace();
		}
		
		return boardlist;
	}
}


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

전체글 갯수 구하기  (0) 2012.08.20
list.jsp 및 결과  (0) 2012.08.19
BoardDao  (0) 2012.08.19
write.jsp  (0) 2012.08.19
수정  (0) 2012.08.19
Posted by NeverTry
Web/게시판2012. 8. 19. 10:45

write.jsp에 쓴 내용을 VO에 담아서 DB에 넣는 로직을 구현하는 BoardDao 파일을 만듭니다.


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

list.jsp 및 결과  (0) 2012.08.19
BoardDao 추가  (0) 2012.08.19
write.jsp  (0) 2012.08.19
수정  (0) 2012.08.19
Mysql 테이블 만들기  (0) 2012.08.18
Posted by NeverTry
Web/게시판2012. 8. 19. 10:05


로그인이 성공했다면 글을 써야 하므로 간단하게 글을 쓰는 창을 만들고 글을 다 쓰면 list.jsp로 넘어간다.

아까 로그인이 성공했을 때 session에 id를 심어놨기 때문에 세션의 아이디를 가지고 와서 뿌려주면 된다.

만약에 session에 값이 들어오지 않았을 경우 login.jsp로 돌아가게 된다.


실행된 화면




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

BoardDao 추가  (0) 2012.08.19
BoardDao  (0) 2012.08.19
수정  (0) 2012.08.19
Mysql 테이블 만들기  (0) 2012.08.18
board  (0) 2012.08.18
Posted by NeverTry