home.jsp

 

 

BoardController

 

 

BoardRepository

 

 

 

BoardSearchAction

더보기
package com.cos.blog.action.board;

import java.io.IOException;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cos.blog.action.Action;
import com.cos.blog.model.Board;
import com.cos.blog.repository.BoardRepository;
import com.cos.blog.util.HtmlParser;
import com.cos.blog.util.Script;

public class BoardSearchAction implements Action {

	@Override
	public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		if(request.getParameter("keyword") == null ||
				request.getParameter("keyword").equals("")) {
			
			Script.back("검색 키워드가 없습니다.", response);
			return;
			
		}
		
		int page = Integer.parseInt(request.getParameter("page"));
		String keyword = request.getParameter("keyword");
		
		BoardRepository boardRepository = BoardRepository.getInstance();
		
//		System.out.println(Integer.parseInt(request.getParameter("page")));
		
		// 2. 3건만 페이징하여 가져오기
//		List<Board> boards = boardRepository.findAll();
		List<Board> boards = boardRepository.findThree(Integer.parseInt(request.getParameter("page")));
		
		if(boards != null) {
			for (Board board : boards) {
				
				String preview = HtmlParser.getContentPreview(board.getContent());
				board.setContent(preview);
				
			}

		}
		
		int lastPage = (boardRepository.count(keyword) - 1) / 3;
		System.out.println(lastPage);
		
		request.setAttribute("boards", boards);
		request.setAttribute("lastPage", lastPage);
		
		RequestDispatcher dis = request.getRequestDispatcher("home.jsp");
		dis.forward(request, response);
		
	}

}

 

 

 

 

 

 

결과

 

'낙서장' 카테고리의 다른 글

면접  (0) 2020.06.10
자바스크립트 새로 가져오기  (0) 2020.06.10
200609  (0) 2020.06.09
부트스트랩과 비슷한 사이트  (0) 2020.06.04
이클립스 자동 import  (0) 2020.06.04

+ Recent posts