jsp 회원등록,수정,삭제,리스트(CRUD) 로직 구현하기 댓글 답변
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
|
else if (command.equals("/board/boardReply.do")) {
String bidx = request.getParameter("bidx");
String originbidx = request.getParameter("originbidx");
String depth = request.getParameter("depth");
String level_ = request.getParameter("level_");
BoardVo bv = new BoardVo();
bv.setBidx(Integer.parseInt(bidx));
bv.setOriginbidx(Integer.parseInt(originbidx));
bv.setDepth(Integer.parseInt(depth));
bv.setLevel_(Integer.parseInt(level_));
request.setAttribute("bv", bv);
RequestDispatcher rd = request.getRequestDispatcher("/board/boardReply.jsp");
rd.forward(request, response);
}else if (command.equals("/board/boardReplyAction.do")) {
String bidx = request.getParameter("bidx");
String originbidx = request.getParameter("originbidx");
String depth = request.getParameter("depth");
String level_ = request.getParameter("level_");
String subject = request.getParameter("subject");
String content = request.getParameter("content");
String writer = request.getParameter("writer");
String ip = InetAddress.getLocalHost().getHostAddress();
HttpSession session = request.getSession();
int midx = (int)session.getAttribute("midx");
//int midx = 1;
BoardVo bv = new BoardVo();
bv.setBidx(Integer.parseInt(bidx));
bv.setOriginbidx(Integer.parseInt(originbidx));
bv.setDepth(Integer.parseInt(depth));
bv.setLevel_(Integer.parseInt(level_));
bv.setSubject(subject);
bv.setContent(content);
bv.setWriter(writer);
bv.setIp(ip);
bv.setMidx(midx);
BoardDao bd = new BoardDao();
int value = bd.replyBoard(bv);
if (value ==1) {
response.sendRedirect(request.getContextPath()+"/board/boardList.do");
}else {
response.sendRedirect(request.getContextPath()+"/board/boardContent.do?bidx="+bidx);
}
|
cs |
Dao 파일
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
|
public int replyBoard(BoardVo bv) {
int value= 0;
String sql1= "update board set depth = depth+1 where originbidx=? and depth >?";
String sql2="insert into board(bidx,originbidx,depth,level_,subject,content,writer,ip,midx)"
+ " VALUES(BIDX_B_SEQ.NEXTVAL,?,?,?,?,?,?,?,?)";
try {
conn.setAutoCommit(false); //�ڵ�Ŀ�� ��� ��
pstmt = conn.prepareStatement(sql1);
pstmt.setInt(1, bv.getOriginbidx());
pstmt.setInt(2, bv.getDepth());
pstmt.executeUpdate();
pstmt = conn.prepareStatement(sql2);
pstmt.setInt(1, bv.getOriginbidx());
pstmt.setInt(2, bv.getDepth()+1);
pstmt.setInt(3, bv.getLevel_()+1);
pstmt.setString(4, bv.getSubject());
pstmt.setString(5, bv.getContent());
pstmt.setString(6, bv.getWriter());
pstmt.setString(7, bv.getIp());
pstmt.setInt(8, bv.getMidx());
value = pstmt.executeUpdate();
conn.commit();
} catch (SQLException e) {
try {
conn.rollback();
} catch (SQLException e1) {
e1.printStackTrace();
}
e.printStackTrace();
} finally {
try {
pstmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return value;
}
|
cs |
Criteria.java
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
|
package damain;
public class Criteria {
private int page; // 페이지
private int perpageNum; // 한페이지에 보여줄 출력 개수
public Criteria() {
this.page = 1;
this.perpageNum = 15;
}
public int getPage() {
return page;
}
public void setPage(int page) {
if(page <= 1) {
this.page =1;
return;
}
this.page = page;
}
public int getPerpageNum() {
return perpageNum;
}
public void setPerpageNum(int perpageNum) {
this.perpageNum = perpageNum;
}
}
|
cs |
searchcreitera.java
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
|
package damain;
public class SearchCriteria extends Criteria {
private String SearchType;
private String keyword;
public SearchCriteria() {
this.SearchType=SearchType;
this.keyword = keyword;
}
public String getSearchType() {
return SearchType;
}
public void setSearchType(String searchType) {
SearchType = searchType;
}
public String getKeyword() {
return keyword;
}
public void setKeyword(String keyword) {
this.keyword = keyword;
}
}
|
cs |
pagemaker
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
|
package damain;
public class PageMaker {
private int totalCount; // 전체 데이터 개수.
private int startPage; // 첫번째 번호
private int endPage; // 마지막 번호
private boolean prev; // 이전버튼
private boolean next; // 다음 버튼.
private int displayPageNum=10; // 밑에 표시되는 페이징
private SearchCriteria scri;
public int getTotalCount() {
return totalCount;
}
public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
calcData();
}
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 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 int getDisplayPageNum() {
return displayPageNum;
}
public void setDisplayPageNum(int displayPageNum) {
this.displayPageNum = displayPageNum;
}
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);
System.out.println("endPage ="+endPage);
startPage = (endPage-displayPageNum)+1;
System.out.println("staryPage ="+startPage);
int tempEndPage = (int)(Math.ceil(totalCount/(double)scri.getPerpageNum()));
System.out.println("tempEndPage ="+tempEndPage);
if(endPage > tempEndPage) {
endPage = tempEndPage;
};
//이전페이지 == > 1일때 거짓 아니면 진실
prev = startPage ==1 ? false:true;
// 다음페이지 == >
next = endPage*scri.getPerpageNum() >=totalCount ? false:true;
}
}
|
cs |
'기존 > 🏀Jsp' 카테고리의 다른 글
[JSP] 예약하기 페이지 구현 (0) | 2022.05.31 |
---|---|
[JSP] 게시판 조회수 구현 (0) | 2022.05.31 |
[JSP] 게시판 삭제 구현하기 (0) | 2022.05.31 |
[JSP] 게시판 수정 구현하기 (0) | 2022.05.31 |
[JSP] 게시판 상세화면 구현하기 (0) | 2022.05.31 |