일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
Tags
- 시계열 특성을 고려한 이상치 탐지
- 최소-최대 정규화
- 데이터의 차원 축소
- 계절성 모델
- 명목형 데이터
- 데이터 수집 및 전처리
- ARIMA 모델링
- custom vision
- 시계열 모델링
- 시계열 상관 분석
- 군집화 시각화 방법
- 데이터 분석 프로세스
- 다변량 분석
- Q-Q 플롯
- 범주형 데이터
- ARMA 모델링
- Z-점수 기반 이상치 탐지
- 상위포지션
- 상자 그림
- 주성분 분석
- 주성분 줄이기
- 지수평활법
- Python
- R과 Python
- 선형 판별 분석 LDA
- 날짜 시간 데이터 전처리
- 다중상관분석
- 상관 분석
- 순서형 데이터
- 데이터 종류에 따른 분석 방법
Archives
- Today
- Total
me made it !
[JSP] 20230321 JSP 게시판 검색 기능 구현하기 본문
반응형
package example1230.domain;
public class SearchCriteria extends Criteria{
private String searchType;
private String keyword;
public String getSearchType() {
return searchType;
}
public void setSearchType(String searchType) {
this.searchType = searchType;
}
public String getKeyword() {
return keyword;
}
public void setKeyword(String keyword) {
this.keyword = keyword;
}
}
package example1230.domain;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
public class PageMaker {
//페이지 네비게이션을 사용하기 위한 기능이 담긴 클래스
private int displayPageNum = 10; //페이지 네비게이션에 나타나는 페이징 수 1 2 3
private int startPage; //페이징의 시작점
private int endPage; //페이징의 끝점
private int totalCount; //전체 게시물 수
private boolean prev; //이전버튼
private boolean next; //다음버튼
private SearchCriteria scri;
public int getDisplayPageNum() {
return displayPageNum;
}
public void setDisplayPageNum(int displayPageNum) {
this.displayPageNum = displayPageNum;
}
public int getStartPage() {
return startPage;
}
public void setStartPage(int startPage) {
this.startPage = startPage;
}
public int getEndPage() {
return endPage;
}
public void setEndPage(int endPage) {
this.endPage = endPage;
}
public int getTotalCount() {
return totalCount;
}
public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
calcData(); //페이징 계산식
}
public boolean isPrev() {
return prev;
}
public void setPrev(boolean prev) {
this.prev = prev;
}
public boolean isNext() {
return next;
}
public void setNext(boolean next) {
this.next = next;
}
public SearchCriteria getScri() {
return scri;
}
public void setScri(SearchCriteria scri) {
this.scri = scri;
}
public void calcData() {
// 시작 페이지 번호
// 끝 페이지 번호
// 이전 다음 버튼 보여주기
endPage = (int)(Math.ceil(scri.getPage()/(double)displayPageNum) * displayPageNum);
startPage = (endPage - displayPageNum)+1 ;
//실제 페이지
int tempEndPage= (int)(Math.ceil(totalCount / (double)scri.getPerPageNum()));
if(endPage > tempEndPage) {
endPage = tempEndPage;
}
prev = (startPage == 1 ? false: true); //false 이면 나타내지 않기
next = (endPage*scri.getPerPageNum() >= totalCount ? false : true);
}
public String encoding(String keyword) {
String str="";
try {
str = URLEncoder.encode(keyword,"UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return str;
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import ="java.util.*" %>
<%@ page import ="example1230.domain.*" %>
<%
ArrayList<BoardVo> blist = (ArrayList<BoardVo>) request.getAttribute("blist");
PageMaker pm =(PageMaker)request.getAttribute("pm");
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>게시판 목록</title>
<style type="text/css">
a:link{
text-decoration:none;
}
</style>
</head>
<body>
게시판 목록
<form name="frm" action="<%=request.getContextPath() %>/board/boardList.do" method="post">
<table style="text-align:left;width:800px;border:0;">
<tr>
<td style="width:600px;"></td>
<td>
<select name="searchType">
<option value="subject">제목</option>
<option value="writer">작성자</option>
</select>
</td>
<td><input type="text" name="keyword" size="10"></td>
<td><input type="submit" name="submit" value="검색"></td>
</tr>
</table>
</form>
<table border=1 style="text-align:left;width:800px;">
<tr>
<td>게시물번호</td>
<td>제목</td>
<td>작성자</td>
<td>날짜</td>
</tr>
<%for(BoardVo bv: blist){ %>
<tr>
<td>
<%=bv.getBidx() %></td>
<td>
<%for(int i = 1; i<=bv.getLevel_(); i++){
out.println(" ");
if(i==bv.getLevel_()){
out.println("ㄴ");
}
} %>
<a href="<%=request.getContextPath()%>/board/boardContents.do?bidx=<%=bv.getBidx() %>"><%=bv.getSubject() %></a></td>
<td><%=bv.getWriter() %></td>
<td><%=bv.getWriteday().substring(0,10) %></td>
</tr>
<%} %>
</table>
<table style="border:0, width:300px;width:800px;">
<tr>
<td style="text-align:right;">
<%if (pm.isPrev()){ %>
<a href="<%=request.getContextPath()%>/board/boardList.do?page=<%=pm.getStartPage()-1%>&searchType=<%=pm.getScri().getSearchType()%>&keyword=<%=pm.encoding(pm.getScri().getKeyword())%>">◀</a>
<%} %>
</td>
<td style="text-align:center;width:300px;">
<%
for (int i= pm.getStartPage(); i <=pm.getEndPage(); i++){
%>
<a href ="<%=request.getContextPath()%>/board/boardList.do?page=<%=i%>&searchType=<%=pm.getScri().getSearchType()%>&keyword=<%=pm.encoding(pm.getScri().getKeyword())%>"><%=i %></a>
<%
}
%>
</td>
<td style="width:200px;text-align:left;">
<%if (pm.isNext()&&pm.getEndPage() > 0){ %>
<a href="<%=request.getContextPath()%>/board/boardList.do?page=<%=pm.getEndPage()+1%>&searchType=<%=pm.getScri().getSearchType()%>&keyword=<%=pm.encoding(pm.getScri().getKeyword())%>">▶</a>
<%} %>
</td>
</tr>
</table>
<a href="<%=request.getContextPath()%>/board/boardWrite.do">글쓰기</a>
</body>
</html>
public int boardTotal(SearchCriteria scri) {
String str="";
if(scri.getSearchType().equals("subject")) {
str="and subject like ?";
}else if (scri.getSearchType().equals("writer")){
str="and writer like ?";
}
String sql ="select count(*) as cnt from board1230 where delyn='n' "+str;
PreparedStatement pstmt = null;
ResultSet rs = null;
int cnt = 0;
try {
pstmt =conn.prepareStatement(sql);
pstmt.setString(1, "%"+scri.getKeyword()+"%");
rs = pstmt.executeQuery();
if (rs.next()) {
cnt = rs.getInt("cnt");
}
} catch (SQLException e) {
e.printStackTrace();
}finally {
try {
rs.close();
pstmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return cnt;
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
if(str.equals("/board/boardList.do")) {
// System.out.println("boardList.do 들어옴");
//검색시 사용하는 값을 추가로 넘겨준다
String searchType =request.getParameter("searchType");
if (searchType == null) searchType ="subject";
String keyword =request.getParameter("keyword");
if (keyword == null) keyword ="";
String page =request.getParameter("page");
if (page == null) {
page = "1";
}
SearchCriteria scri = new SearchCriteria();
scri.setPage(Integer.parseInt(page)); //넘어온 page 값을 cri에 담는다.
scri.setSearchType(searchType);
scri.setKeyword(keyword);
BoardDao bd = new BoardDao();
ArrayList<BoardVo> blist = bd.boardSelectAll(scri);
int cnt = bd.boardTotal(scri);
// System.out.println("cnt:"+cnt);
PageMaker pm = new PageMaker();
pm.setScri(scri);
pm.setTotalCount(cnt);
request.setAttribute("blist", blist);
request.setAttribute("pm", pm);
RequestDispatcher rd = request.getRequestDispatcher("/board/boardList.jsp");
rd.forward(request, response); //forward 방식 : 같은 영역안에 있는 다른 공간에 정보를 넘겨줌
반응형
'TIL > JSP' 카테고리의 다른 글
[JSP] 20230322 JSP 파일 첨부된 게시 글 구현하기 (0) | 2023.03.22 |
---|---|
[JSP] 20230322 JSP 게시판 파일 첨부 (0) | 2023.03.22 |
[JSP] 20230321 JSP 게시판 페이징 (0) | 2023.03.21 |
[JSP] 20230320 JSP 페이징 (0) | 2023.03.20 |
[JSP] 20230320 JSP 답글은 구분하기 위해 제목 앞에 띄어쓰기와 'ㄴ '넣기 (0) | 2023.03.20 |