programming/jsp
JSP - 작성자, 제목, 내용과 일치하는 항목 찾기 (2)
히연쓰
2021. 5. 17. 15:34
JSP - 작성자, 제목, 내용과 일치하는 항목 찾기 (1) 이후에 다시 적어봐야겠다 ~ !
자 이제 삭제 버튼을 누른 것 부터 시작해보면
7 ) board_delete.jsp
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
<%@page import="com.heeyeon.model.BoardBean"%>
<%@page import="com.heeyeon.model.BoardDao"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="css/layout.css">
<script src="js/jquery-3.6.0.min.js"></script>
<script src="js/join.js" defer></script>
</head>
<body>
<%
int no = Integer.parseInt(request.getParameter("no"));
BoardDao boardDao = new BoardDao();
BoardBean boardBean = boardDao.getSelectOne(no);
//no를 통해 뽑혀진 하나의 row값을 boardBean의 속성으로 리턴 받았다.
%>
<div class="formBox">
<h2>자유게시판</h2>
<form action="board_delete_action.jsp" id="joinForm" method="POST">
<table>
<colgroup>
<col style="width:150px">
<col style="width:850px">
</colgroup>
<tbody>
<!-- <tr> -->
<!-- <th>ID</th> -->
<%-- <td><%=boardBean.getId()%></td> --%>
<!-- </tr> -->
<tr>
<th>NAME</th>
<td><input type="text" name="name" value="<%=boardBean.getName()%>" readonly></td>
</tr>
<tr>
<th>SUBJECT</th>
<td><input type="text" name="subject" value="<%=boardBean.getSubject()%>"></td>
</tr>
<tr>
<th>PASSWORD</th>
<td><input type="password" name="password" id="userPassword"></td>
</tr>
<tr>
<th>CONTENTS</th>
<td>
<textarea name="contents" id="contents" value=""><%=boardBean.getContents()%></textarea>
</td>
</tr>
</tbody>
</table>
<div class="btns">
<input type="hidden" name="no" value="<%=boardBean.getNo()%>">
<input type="submit" value="확인">
<input type="reset" value="취소">
<a href = "board_list.jsp">목록</a>
</div>
</form>
</div>
</body>
</html>
|
cs |
board_modify.jsp와 거의 같다고 볼 수 있다.
이것도 password가 일치하면
8) board_delete_action.jsp
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
<%@page import="com.heeyeon.model.BoardDao"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<!-- 넘어온 no값을 받아서.... -->
<!-- BoardDao에 메서드 두개 -->
<!-- 1. no를 통해서 비밀번호 찾기... -->
<!-- 2. 넘어온 비밀번호랑 찾은 비밀번호랑 같으면 -->
<!-- 3. BoardDao의 update메소드를 실행 -->
<%
request.setCharacterEncoding("UTF-8");
%>
<jsp:useBean id="boardBean" class="com.heeyeon.model.BoardBean">
<jsp:setProperty name="boardBean" property="*" />
</jsp:useBean>
<%
int no = Integer.parseInt(request.getParameter("no"));
BoardDao boardDao = new BoardDao();
String dbPassword = boardDao.getPassword(no);// 넘겨받은 no를 통해 비밀번호 찾기....
if(dbPassword.equals(boardBean.getPassword())){
//비밀번호가 같으니까....
//boardDao의 updateBoard를 실행
int result = boardDao.deleteBoard(no);
if(result > 0) {
%>
<script>
alert("글이 삭제되었습니다.");
location.href="board_list.jsp";
</script>
<%
} else {
%>
<script>
alert("비밀번호를 확인해 주세요.");
//location.href="board_delete.jsp";
history.back();
</script>
<% }
}
%>
</body>
</html>
|
cs |
글이 삭제된다.
그리고 이 글의 하이라이트 ? 인 .. 작성자, 제목, 내용 과 일치하는 항목을 찾는 것 ㅋㅋㅋ .. 어렵고 어렵다
9 ) board_search_list.jsp
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
<%@page import="com.heeyeon.model.BoardBean"%>
<%@page import="com.heeyeon.model.BoardDao"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="preconnect" href="https://fonts.gstatic.com">
<link
href="https://fonts.googleapis.com/css2?family=Noto+Sans+KR:wght@100;300;400;500;700;900&display=swap"
rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons"
rel="stylesheet">
<link rel="stylesheet" href="css/layout.css">
</head>
<body>
<%
String searchSelect = request.getParameter("searchSelect");
String searchWord = request.getParameter("searchWord");
String clickedPage = request.getParameter("clickedPage");
if(clickedPage==null){
clickedPage = "1";
}
%>
<%-- searchSelect===<%=searchSelect %><br> --%>
<%-- searchWord===<%=searchWord %> --%>
<%
int pagePerCount = 5;
int total = 0;
int numbering = 0;//no는 sequence로 정해지는 값이므로 삭제가 되면 없어져 버린다. 그래서 중간에 이가빠진거처럼 보인다. 그걸 해결하기 위해서 쓰는거
int currentPage = Integer.parseInt(clickedPage);
int start = (currentPage - 1)*pagePerCount + 1;
int end = currentPage*pagePerCount;
ArrayList<BoardBean> boardList = null;
BoardDao boardDao = new BoardDao();
boardList = boardDao.showAllSearchBoard(start, end, searchSelect, searchWord);
total = boardDao.getSearchTotal(searchSelect,searchWord);
//30
numbering = total - (currentPage - 1)*pagePerCount;
%>
<div class="formBox" id="list">
<h2>자유게시판</h2>
<table>
<colgroup>
<col style="width: 50px">
<col style="width: 150px">
<col style="width: 150px">
<col style="width: 950px">
</colgroup>
<thead>
<tr>
<th>NO</th>
<th>ID</th>
<th>NAME</th>
<th>SUBJECT</th>
</tr>
</thead>
<tbody>
<%
for(int i=0;i<boardList.size();i++){
BoardBean boardBean = boardList.get(i);
%>
<tr>
<%--<td><%=boardBean.getNo()%></td> --%>
<td><%=(numbering - i)%></td>
<td><%=boardBean.getId()%></td>
<td><%=boardBean.getName()%></td>
<td><a href="board_view.jsp?no=<%=boardBean.getNo()%>"><%=boardBean.getSubject()%></a></td>
</tr>
<%
}
%>
</tbody>
</table>
<div class="pagination">
<!--<a href=""><span class="material-icons">chevron_left</span></a> -->
<!--<a href="" class="clicked">1</a> -->
<!--<a href="" class="">2</a> -->
<!--<a href="" class="">3</a> -->
<!--<a href=""><span class="material-icons">chevron_right</span></a> -->
<%
int paginationTotal = ((int) Math.floor(total / pagePerCount)) + 1;
int pagePerGroup = 3;
int startPage = 1;
if(currentPage % pagePerGroup!=0){
startPage = ((int) (currentPage / pagePerGroup)) * pagePerGroup + 1;
} else {
startPage = ((int) (currentPage / pagePerGroup) - 1) * pagePerGroup + 1;
}
int endPage = startPage + pagePerGroup - 1;
if(endPage > paginationTotal){
endPage = paginationTotal;
}
if (startPage > pagePerGroup) {
%>
<a href="board_search_list.jsp?clickedPage=<%=(startPage - pagePerGroup)%>&searchSelect=<%=searchSelect%>&searchWord=<%=searchWord%>">
<span class="material-icons">chevron_left</span>
</a>
<%
}
for(int i = startPage; i<=endPage;i++){
%>
<a href="board_search_list.jsp?clickedPage=<%=i%>&searchSelect=<%=searchSelect%>&searchWord=<%=searchWord%>"><%=i%></a>
<%
}
if (endPage < paginationTotal) {
%>
<a href="board_search_list.jsp?clickedPage=<%=(startPage + pagePerGroup)%>&searchSelect=<%=searchSelect%>&searchWord=<%=searchWord%>">
<span class="material-icons">chevron_right</span>
</a>
<%
}
%>
</div>
<div class="searchBox">
<form action="board_search_list.jsp">
<select name="searchSelect" class="select">
<option value="id">작성자</option>
<option value="subject">제목</option>
<option value="contents">내용</option>
</select> <input type="text" name="searchWord" value="" class="searchWord">
<input type="submit" value="검색">
</form>
</div>
<div class="btns">
<a href="board_write.jsp" id="join">글쓰기</a>
</div>
</div>
</body>
</html>
|
cs |
나는 작성자 장동건만 검색을 원하여 작성자를 장동건을 치고 검색 버튼을 누르면 !
이렇게 작성자가 장동건만 나오는 것을 확인할 수 있다.
자바 파일
진짜 학원에서 하면 피할 수 없는 저 빨간 X ........ 늘 실행만 잘되면 됐지 뭐 하지만
거슬리고 또 거슬리는 ㅋㅋ..
뭐 이렇게 마무리가 되겠다.