서블릿과 JSP 를 이용하여 목적별 데이트 코스를 추천해 주는 웹을 개발하였다.
제가 맡은 기능은 사용자 간의 커뮤니티인 게시판을 만는 것이었습니다.
Servlet, JSP 로 CRUD 게시판 구현, Ajax 를 통해 비동기식 댓글 CRUD 및
사이드 인기 게시글, 검색 부분을 구현하였습니다.
부가기능으로 관리자가 공지한 글이 커뮤니티 상단에 노출 시켜, 드롭다운 방식으로 게시글을 조회 할 수 있습니다.
03. 인기 Top 5 글 노출 및 검색 기능
$(function(){
selectTopList(); // 열자 마자 호출 하고
$(".thumbnail").click(function(){
var bno = $(this).children().eq(0).val();
location.href="<%=contextPath%>/detail.bo?bno="+bno;
})
setInterval(selectTopList, 5000)
$("#thumbList").on("click",".thumb",function(){
var bno = $(this).children().eq(0).val();
location.href = "<%=contextPath%>/detail.bo?bno="+bno;
})
})
function selectTopList(){
$.ajax({
url : "topList.do",
type: "get",
success:function(list){
console.log(list);
console.log(list[0].titleImg);
console.log(list[0].boardTitle);
var contextPath = "<%=contextPath%>";
var value = "";
for(var i in list){
var tmp = list[i].boardTitle;
var time = list[i].createDate;
console.log(time);
value += '<div class="blog__sidebar__recent__item__pic thumb" >'+
'<input type="hidden" value="' +list[i].boardNo+ '">'+
'<img src="'+contextPath+'/resources/board_upfiles/' + list[i].titleImg + '" width="80px" height="70px">'+
'</div><div class="blog__sidebar__recent__item__text"><span class="lanking">'+ (++i)+
'</span></div><h6 class="thumb">'+ tmp +'</h6>'+
'<p><i class="fa fa-clock-o"></i> '+time+'</p></div>';
}
console.log(value);
$("#thumbList").html(value).trigger("create");
},
error:function(){
console.log("ajax통신실패");
}
})
}
TopListServlet
package semiProject.com.kh.board.controller;
import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.google.gson.Gson;
import semiProject.com.kh.board.model.service.BoardService;
import semiProject.com.kh.board.model.vo.Board;
/**
* Servlet implementation class TopListServlet
*/
@WebServlet("/topList.do")
public class TopListServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public TopListServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
ArrayList<Board> list = new BoardService().selectTopList();
response.setContentType("application/json; charset=utf-8");
new Gson().toJson(list, response.getWriter());
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
BoardSearchSerlvet
package semiProject.com.kh.board.controller;
import java.io.IOException;
import java.util.ArrayList;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import semiProject.com.kh.board.model.service.BoardService;
import semiProject.com.kh.board.model.vo.Board;
import semiProject.com.kh.board.model.vo.PageInfo;
import semiProject.com.kh.notice.model.vo.Notice;
/**
* Servlet implementation class BoardSearchServlet
*/
@WebServlet("/search.bo")
public class BoardSearchServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public BoardSearchServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//공지사항도 넘겨줘야 하니깐
ArrayList<Notice> nlist = new BoardService().selectNList();
//검색내용을 스트링에 담아서
String searchWord = request.getParameter("search");
//페이지랑 검색 내용을 함께 넘셔서 , 새로운 페이지로 넘겨서 받아보자
ArrayList<Board> searchBoard = new BoardService().searchWord(searchWord);
if(!searchBoard.isEmpty() && !searchWord.equals(" "))
{
request.setAttribute("searchBoard", searchBoard);
request.setAttribute("searchWord", searchWord);
//VIEW 단으로 넘겨주는 객체들
request.setAttribute("nlist", nlist);
request.setAttribute("msg", " ");
request.getRequestDispatcher("views/board/boardSearchList.jsp").forward(request, response);
}
else
{
request.setAttribute("msg", "검색된 결과가 없습니다. 다시 검색해 주세요");
request.getRequestDispatcher("views/common/errorPage.jsp").forward(request, response);
}
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}
}
쿼리문
selectTopList=SELECT * FROM (SELECT BOARD_NO, BOARD_TITLE, COUNT, CHANGE_NAME, CREATE_DATE \
FROM BOARD JOIN (SELECT * FROM ATTACHMENT \
WHERE FILE_NO IN( \
SELECT MIN(FILE_NO) FILE_NO FROM ATTACHMENT WHERE STATUS='Y' GROUP BY REF_BNO)) ON (REF_BNO = BOARD_NO) \
WHERE BOARD.STATUS='Y' ORDER BY COUNT DESC) WHERE ROWNUM <= 5
searchWord=SELECT * FROM (SELECT BOARD_NO, BOARD_TITLE, USER_NO, COUNT,CREATE_DATE, CHANGE_NAME \
FROM BOARD \
JOIN (SELECT * FROM ATTACHMENT \
WHERE FILE_NO IN( \
SELECT MIN(FILE_NO) FILE_NO FROM ATTACHMENT WHERE STATUS='Y' GROUP BY REF_BNO)) ON (REF_BNO = BOARD_NO)\
JOIN MEMBER ON BOARD_WRITER = USER_NO \
WHERE BOARD.STATUS='Y' ORDER BY BOARD_NO DESC) where board_title like '%' || ? || '%' Order by board_no
'세미프로젝트' 카테고리의 다른 글
세미 프로젝트[어디어디] (0) | 2021.11.29 |
---|---|
세미프로젝트 [어디어디] (0) | 2021.11.29 |
세미프로젝트 [어디어디] 공지사항 상단 조회 (0) | 2021.11.28 |