오늘은 JSP에서 작성자, 제목, 내용과 일치하는 항목을 찾는 JSP 를 작성해보겠따 우하하
사실 아직 도움 없이는 잘하지는 못하지만 (잘) 하려고 노력 ? 중....... 일 것이다 아마도 ..
1) BoardBean 작성하기
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
|
package com.heeyeon.model;
public class BoardBean {
private int no;
private String id;
private String name;
private String subject;
private String password;
private String contents;
public BoardBean() {
super();
}
public BoardBean(int no, String id, String name, String subject, String password, String contents) {
super();
this.no = no;
this.id = id;
this.name = name;
this.subject = subject;
this.password = password;
this.contents = contents;
}
public int getNo() {
return no;
}
public void setNo(int no) {
this.no = no;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSubject() {
return subject;
}
public void setSubject(String subject) {
this.subject = subject;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getContents() {
return contents;
}
public void setContents(String contents) {
this.contents = contents;
}
@Override
public String toString() {
return "boardBean [no=" + no + ", id=" + id + ", name=" + name + ", subject=" + subject + ", password="
+ password + ", contents=" + contents + "]";
}
}
|
cs |
2) BoardDao 작성하기
주의할 점은 이 파일은 기본?파일이 아니라 각각의 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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
package com.heeyeon.model;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
public class BoardDao {
String driver = "oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@localhost:1521:xe";
String id= "heeyeon0";
String pw ="1234";
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
private void getConnection() {
try {
Class.forName(driver);
con = DriverManager.getConnection(url,id,pw);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (SQLException e) {
e.printStackTrace();
}
}
private void close(ResultSet rs,PreparedStatement pstmt, Connection con) {
try {
if(rs!=null) rs.close();
if(pstmt!=null) pstmt.close();
if(con!=null) con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
private void close(PreparedStatement pstmt, Connection con) {
try {
if(pstmt!=null) pstmt.close();
if(con!=null) con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public int insertBoard(BoardBean boardBean) {
int result = 0;
try {
getConnection();
String sql = "INSERT INTO BOARD03 VALUES (BOARD03_SEQ.NEXTVAL,?,?,?,?,?)";
pstmt = con.prepareStatement(sql);
pstmt.setString(1, boardBean.getId());
pstmt.setString(2, boardBean.getName());
pstmt.setString(3, boardBean.getSubject());
pstmt.setString(4, boardBean.getPassword());
pstmt.setString(5, boardBean.getContents());
result = pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
close(pstmt,con);
}
return result;
}
public ArrayList<BoardBean> showAllBoard(int start, int end) {
ArrayList<BoardBean> boardList = new ArrayList<BoardBean>();
try {
getConnection();
//String sql = "SELECT * FROM BOARD03";
String sql ="SELECT * FROM "
+ "(SELECT ROWNUM AS NUM, B.* FROM ( "
+ " SELECT * FROM BOARD03 ORDER BY ID DESC "
+ ") B) "
+ "WHERE NUM >= ? AND NUM <= ?";
pstmt = con.prepareStatement(sql);
pstmt.setInt(1, start);
pstmt.setInt(2, end);
rs = pstmt.executeQuery();
while(rs.next()) {
BoardBean boardBean = new BoardBean();
boardBean.setNo(rs.getInt("no"));
boardBean.setId(rs.getString("id"));
boardBean.setName(rs.getString("name"));
boardBean.setSubject(rs.getString("subject"));
boardBean.setPassword(rs.getString("password"));
boardBean.setContents(rs.getString("contents"));
boardList.add(boardBean);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
close(rs,pstmt,con);
}
return boardList;
}
//검색 결과를 boardBean으로 리턴하는 메서드
public ArrayList<BoardBean> showAllSearchBoard(int start , int end , String seachField , String query) {
ArrayList<BoardBean> boardList = new ArrayList<BoardBean>();
try {
getConnection();
String sql = "SELECT * FROM "
+ "(SELECT ROWNUM AS NUM, B.* FROM "
+ "(SELECT * FROM BOARD03 WHERE "+seachField+" LIKE ? ORDER BY NO DESC) B ) "
+ "WHERE NUM >= ? AND NUM <= ?";
pstmt = con.prepareStatement(sql);
pstmt.setString(1,"%"+query+"%");
pstmt.setInt(2,start);
pstmt.setInt(3,end);
rs = pstmt.executeQuery();
while(rs.next()) {
BoardBean boardBean = new BoardBean();
boardBean.setNo(rs.getInt("no"));
boardBean.setId(rs.getString("id"));
boardBean.setName(rs.getString("name"));
boardBean.setSubject(rs.getString("subject"));
boardBean.setPassword(rs.getString("password"));
boardBean.setContents(rs.getString("contents"));
boardList.add(boardBean);
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
close(rs,pstmt,con);
}
return boardList;
}
public BoardBean getSelectOne(int no) {
BoardBean boardBean = new BoardBean();
//1. DB 연결 //2. sql 작성 //3. 실행후 결과 반환 //4. 자원반납
try {
getConnection();
String sql = "SELECT * FROM BOARD03 WHERE NO = ?";
pstmt = con.prepareStatement(sql);
pstmt.setInt(1,no);
rs = pstmt.executeQuery();
if(rs.next()) {
boardBean.setNo(rs.getInt("no"));
boardBean.setId(rs.getString("id"));
boardBean.setName(rs.getString("name"));
boardBean.setSubject(rs.getString("subject"));
boardBean.setPassword(rs.getString("password"));
boardBean.setContents(rs.getString("contents"));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
close(rs,pstmt,con);
}
return boardBean;
}
//넘어온 boardDao를 업데이트 하기 위한 메서드
public int updateBoard(BoardBean boardBean) {
int result = 0;
try {
getConnection();
String sql = "UPDATE BOARD03 SET NAME=?,SUBJECT=?,CONTENTS=? WHERE NO = ?";
pstmt = con.prepareStatement(sql);
pstmt.setString(1,boardBean.getName());
pstmt.setString(2,boardBean.getSubject());
pstmt.setString(3,boardBean.getContents());
pstmt.setInt(4,boardBean.getNo());
result = pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
close(pstmt,con);
}
return result;
}
//넘어온 no를 통해 패스워드 찾는 메서드
public String getPassword(int no) {
String password = "";
try {
getConnection();
String sql = "SELECT PASSWORD FROM BOARD03 WHERE NO = ?";
pstmt = con.prepareStatement(sql);
pstmt.setInt(1, no);
rs = pstmt.executeQuery();
if(rs.next()) {
password = rs.getString("PASSWORD");
}
} catch (SQLException e) {
e.printStackTrace();
}
return password;
}
public int deleteBoard(int no) {
int result = 0;
try {
getConnection();
String sql = "DELETE FROM BOARD03 WHERE NO = ?";
pstmt = con.prepareStatement(sql);
pstmt.setInt(1, no);
result = pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
close(pstmt,con);
}
return result;
}
//검색된 게시물 갯수 가져오기
public int getSearchTotal(String seachField, String query) {
int total = 0;
try {
getConnection();
//SUBqUERY를 통해서 먼저 검색 결과를 얻고 그 결과값이 몇개인지를 COUNT()함수를 통해서 갯수를 도출
String sql = "SELECT COUNT(*) AS TOTAL FROM (SELECT * FROM BOARD03 WHERE "+seachField+" LIKE ?)";
//String sql = "SELECT COUNT(*) FROM BOARD03 WHERE "+seachField+" LIKE ?";
pstmt = con.prepareStatement(sql);
pstmt.setString(1, "%"+query+"%");
rs = pstmt.executeQuery();
if(rs.next()) {
total = rs.getInt("TOTAL");
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
close(rs,pstmt,con);
}
return total;
}
//전체 게시물 갯수 가져오기
public int getTotal() {
int total = 0;
try {
getConnection();
String sql = "SELECT COUNT(*) AS TOTAL FROM BOARD03";
pstmt = con.prepareStatement(sql);
rs = pstmt.executeQuery();
if(rs.next()) {
total = rs.getInt("TOTAL");
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
close(rs,pstmt,con);
}
return total;
}
}
|
cs |
3) layout.css -> 만들어놓은 css
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
148
149
150
151
152
153
154
155
156
157
|
@charset "UTF-8";
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: "Noto Sans KR";
}
a {
text-decoration:none;
color:inherit;
}
table {
border: none;
border-collapse: collapse;
border-top: 1px solid #d9d9d9;
}
table tr th {
background-color: #f8f8f8;
}
table tr th, table tr td {
padding: 15px;
border-bottom: 1px solid #d9d9d9;
}
table tr td input[type="text"], table tr td input[type="password"],
table tr td select {
height: 30px;
border: 1px solid #d9d9d9;
padding: 5px;
border-radius: 3px;
width: 50%;
}
table tr td select {
width: 120px;
}
.formBox {
width: 1000px;
margin: 100px auto;
}
.formBox h2 {
margin-bottom: 50px;
text-align: center;
}
.formBox .btns {
text-align: center;
margin-top: 50px;
}
.formBox .btns * {
display: inline-block;
width: 150px;
height: 50px;
line-height:50px;
border: none;
border-radius: 5px;
box-shadow: 0 5px 5px rgba(0, 0, 0, 0.1);
font-size: 16px;
font-weight: 500;
background-color: rgb(109, 109, 109);
color: #fff;
}
.formBox #contents {
width:100%;
min-height:400px;
resize: none;
border: 1px solid #d9d9d9;
padding: 5px;
}
.formBox .btns #join {
background-color: rgb(1, 121, 177);
}
.formBox .pagination {
margin-top: 50px;
text-align: center;
}
.formBox .pagination a {
display: inline-block;
width:30px;
height:30px;
background-color: #000;
color:#fff;
font-size: 14px;
line-height: 30px;
border-radius: 3px;
}
#list tbody td {
text-align: center;
}
#list tbody tr:hover {
background-color:#000;
color:#fff;
}
.formBox .pagination a.clicked {
background-color: rgb(1, 121, 177);
}
.formBox .pagination a .material-icons {
width:30px;
height:30px;
line-height: 30px;
vertical-align: top;
}
.searchBox {
text-align: center;
width:100%;
background-color: #f8f8f8;
border: 1px solid #d9d9d9;
padding:30px 0;
margin-top:50px;
}
.searchBox .searchWord{
height:40px;
min-width:300px;
display: inline-block;
margin:0;
padding:0;
border:1px solid #d9d9d9;
vertical-align: top;
}
.searchBox .select{
height:40px;
line-height: 40px;
display: inline-block;
margin:0;
padding:0;
border:1px solid #d9d9d9;
padding:0 40px 0 20px;
appearance: none;
background: url("../images/bgSelect.png") no-repeat right 0 top 50%;
background-size: 32px;
}
.searchBox input[type="submit"] {
height:40px;
background-color: #000;
color:#fff;
border-radius: 3px;
padding:0 20px;
border-color:#000;
}
|
cs |
이제부터 글 작성, 수정, 삭제, 목록 의 파일을 작성해보자.
1) board_write.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
|
<%@ 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">
<script src="js/jquery-3.6.0.min.js"></script>
<script src="js/join.js" defer></script>
</head>
<body>
<div class="formBox">
<h2>자유게시판</h2>
<form action="board_write_action.jsp" id="joinForm" method="POST">
<table>
<colgroup>
<col style="width:150px">
<col style="width:850px">
</colgroup>
<tbody>
<tr>
<th>ID</th>
<td><input type="text" name="id" id="userID"></td>
</tr>
<tr>
<th>NAME</th>
<td><input type="text" name="name" id="userName" value=""></td>
</tr>
<tr>
<th>SUBJECT</th>
<td><input type="text" name="subject" id="subject" value=""></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"></textarea>
</td>
</tr>
</tbody>
</table>
<div class="btns">
<input type="button" value="확인" id="join">
<input type="reset" value="취소" id="cancel">
</div>
</form>
</div>
</body>
</html>
|
cs |
2) board_write_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
|
<%@ 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>
<%
request.setCharacterEncoding("UTF-8");
%>
<jsp:useBean id="boardBean" class="com.heeyeon.model.BoardBean">
<jsp:setProperty name="boardBean" property="*" />
</jsp:useBean>
<%
BoardDao boardDao = new BoardDao();
int result = boardDao.insertBoard(boardBean);
if(result>0) {
%>
<script>
alert("글이 등록되었습니다");
location.href="board_list.jsp";
</script>
<%
} else {
%>
<script>
alert("등록 실패");
history.back();
</script>
<%
}
%>
</body>
</html>
|
cs |
3 ) board_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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
|
<%@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"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!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>
<!-- 전체 게시물의 갯수를 알아야 한다. 34 -->
<!-- 한번에 보여줄 게시물의 갯수도 알야 한다. 10 -->
<%
String searchSelect = request.getParameter("searchSelect");
String searchWord = request.getParameter("searchWord");
String clickedPage = request.getParameter("clickedPage");
String isMode = request.getParameter("isMode");
if(searchSelect==null) searchSelect="";
if(searchWord==null) searchWord="";
if(isMode==null) isMode="";
System.out.println("isMode==="+isMode);
System.out.println(searchSelect+"==="+searchWord);
//한 페이지에 보여질 게시글 수!
int pagePerCount = 10;
//request로 넘어오는 페이지 번호 즉 클릭한 페이지 번호
//값이 없을때 1로 세팅
if (clickedPage == null) {
clickedPage = "1";
}
//전체 게시글 수
int total = 0;
//테이블의 no에 뿌려질 번호 원래는 getNo를 뿌리고 있는데
//중간에 삭제되거나 순서가 바뀌면 엉망이 되어서 보기 싫음
int numbering = 0;
int currentPage = Integer.parseInt(clickedPage);
//전체 게스글수를 boardDao의 getTotal메서드를 통해서 얻어옴...
int start = (currentPage - 1) * pagePerCount + 1;
int end = currentPage * pagePerCount;
ArrayList<BoardBean> boardList = null;
BoardDao boardDao = new BoardDao();
if(isMode.equals("search")){
//검색 버튼을 눌러서 검색 결과를 가져오기
boardList = boardDao.showAllSearchBoard(start, end, searchSelect, searchWord);
total = boardDao.getSearchTotal(searchSelect,searchWord);
System.out.println("현재는 검색모드입니다.");
} else {
//이건 그냥 전체 게시글 가져오기
boardList = boardDao.showAllBoard(start, end);
total = boardDao.getTotal();
System.out.println("현재는 노멀모드입니다.");
}
numbering = total - (currentPage - 1) * pagePerCount;
//board_list.jsp 원래 전체 게시글을 출력하기 위해 만듬
//board_search_list.jsp 원래 전체 게시글을 출력하기 위해 만듬
//검색 결과를 출력하기 위해 만듬
%>
<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">
<!-- 300 10 -->
<%
// pagination쪽에 뿌려질 수 있는 최대의 갯수
int paginationTotal = (int) Math.floor(total / pagePerCount) + 1;
// pagination쪽에 한번에 보여지는 pager의 갯수
// 3이면< 1,2,3 > 4이면 < 1,2,3,4 > 5이면 < 1,2,3,4,5 >
int pageGroup = 3;
// 시작 번호
int startPage = 1;
//시작 페이지가 0이 되면 안됨 1 부터 시작해야함
if (currentPage % pageGroup != 0) {
startPage = (int) (currentPage / pageGroup) * pageGroup + 1;
} else {
startPage = ((int) (currentPage / pageGroup) - 1) * pageGroup + 1;
}
int endPage = startPage + pageGroup - 1;
if (endPage > paginationTotal) {
endPage = paginationTotal;
}
//시작 번호(startPage)가 pageGroup보다 크다면 그러니까 pageGroup는 고정값을 가진다. 우리가 정해놓은 값으로 세팅 현재는 3
// 시작 번호가 3보다 크다는건 오른쪽에 있는 다음 페이지를 눌렀다는 걸 의미 이때 이전 페이지로 돌아갈 수 있게 prev가 보여야함.
if (startPage > pageGroup) {
%>
<a href="board_list.jsp?clickedPage=<%=(startPage - pageGroup)%>&searchSelect=<%=searchSelect%>&searchWord=<%=searchWord%>&isMode=<%=isMode%>">
<span class="material-icons">chevron_left</span>
</a>
<%
}
for (int i = startPage; i <= endPage; i++) {
//현재 누른 페이지랑 i가 같으면 clicked라는 클래스 줘서 파랗게 표시....
if (i == currentPage) {
%>
<a href="board_list.jsp?clickedPage=<%=i%>&searchSelect=<%=searchSelect%>&searchWord=<%=searchWord%>&isMode=<%=isMode%>" class="clicked"><%=i%></a>
<%
} else {
%>
<a href="board_list.jsp?clickedPage=<%=i%>&searchSelect=<%=searchSelect%>&searchWord=<%=searchWord%>&isMode=<%=isMode%>"><%=i%></a>
<%
}
}
// endPage paginationTotal보다 작다면
// paginationTotal는 고정값을 가진다. 전체 row의 갯수 getTotal()을 통해 얻어온 값을 pagePerCount 로 나눈값
// 끝번호가 paginationTotal 작다는건 아직 마지막 까지 가지 못한것이므로 다음 페이지를 볼 수 있는 next가 보여야함.
if (endPage < paginationTotal) {
%>
<a href="board_list.jsp?clickedPage=<%=(startPage + pageGroup)%>&searchSelect=<%=searchSelect%>&searchWord=<%=searchWord%>&isMode=<%=isMode%>">
<span class="material-icons">chevron_right</span>
</a>
<%
}
%>
</div>
<div class="searchBox">
<form action="board_list.jsp">
<input type="hidden" name="isMode" value="search">
<select name="searchSelect" class="select">
<option value="name" ${param.searchSelect == "name"?"selected":""} >작성자</option>
<option value="subject" ${param.searchSelect == "subject"?"selected":""}>제목</option>
<option value="contents" ${param.searchSelect == "contents"?"selected":""}>내용</option>
</select> <input type="text" name="searchWord" value="${param.searchWord }" class="searchWord">
<input type="submit" value="검색">
</form>
</div>
<div class="btns">
<a href="board_write.jsp" id="join">글쓰기</a>
</div>
</div>
</body>
</html>
|
cs |
나는 이 글을 작성하기 전에 이런거 저런거 막 넣어놔서 데이터 값들이 많음. .. ..
각각의 subject를 클릭하면 board_view로 이동
4) board_view.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
|
<%@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_write_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><%=boardBean.getName()%></td>
</tr>
<tr>
<th>SUBJECT</th>
<td><%=boardBean.getSubject()%></td>
</tr>
<!-- <tr> -->
<!-- <th>PASSWORD</th> -->
<!-- <td><input type="password" name="password" id="userPassword"></td> -->
<!-- </tr> -->
<tr>
<th>CONTENTS</th>
<td>
<%-- <%=boardBean.getContents()%> --%>
<textarea name="contents" id="contents" readonly><%=boardBean.getContents()%></textarea>
</td>
</tr>
</tbody>
</table>
<div class="btns">
<!-- <input type="button" value="확인" id="join"> -->
<!-- <input type="reset" value="취소" id="cancel"> -->
<a href = "board_list.jsp">목록</a>
<a href = "board_modify.jsp?no=<%=boardBean.getNo()%>">수정</a>
<a href = "board_delete.jsp?no=<%=boardBean.getNo()%>">삭제</a>
</div>
</form>
</div>
</body>
</html>
|
cs |
먼저 수정을 해보면,
5) board_modify.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_modify_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 |
6) board_modify_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
|
<%@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.updateBoard(boardBean);
if(result > 0) {
%>
<script>
alert("글이 수정되었습니다.");
location.href="board_list.jsp";
</script>
<%
} else {
%>
<script>
alert("비밀번호를 확인해 주세요.");
//location.href="board_modify.jsp";
history.back();
</script>
<% }
}
%>
</body>
</html>
|
cs |
비밀번호가 일치하면 글이 수정된다.
나는 헬로우의 subject를 인사 - > 인사 에서 수정했음으로 변경함.
흠 ,, 뭔가 버벅거리는게 너무 많이 적었나보당
2편을 적겠숨니다 ..
'programming > jsp' 카테고리의 다른 글
mvc패턴 (0) | 2021.05.17 |
---|---|
JSP - 작성자, 제목, 내용과 일치하는 항목 찾기 (2) (0) | 2021.05.17 |
JSTL - 기초편5 (2) | 2021.05.14 |
JSTL - 구구단 출력 (0) | 2021.05.13 |
JSTL - 기초편4 (0) | 2021.05.13 |