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
|
else if (command.equals("/board/boardContent.do")) { // 게시판 내용보기
String bidx = request.getParameter("bidx");
System.out.println("bidx="+bidx);
int bidx_ = Integer.parseInt(bidx);
System.out.println("bidx="+bidx_);
// 각각의 bidx 의 값을꺼냄
BoardDao bd =new BoardDao();
// 게시판 BIDX 번호만으로 내용 출력하기
BoardVo bv = bd.boardSelectOne(bidx_);
System.out.println("bv="+bv);
request.setAttribute("bv", bv);
RequestDispatcher rd = request.getRequestDispatcher("/board/boardContent.jsp");
rd.forward(request, response);
|
cs |
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
|
public BoardVo boardSelectOne(int bidx) {
boardCnt(bidx); // 글작성 조회수 같이 실행해주기.. 같은 bidx 이니
BoardVo bv = null;
ResultSet rs= null;
String sql="select * from board where bidx=?";
try {
pstmt = conn.prepareStatement(sql);
pstmt.setInt(1, bidx);
rs = pstmt.executeQuery();
if(rs.next()) {
bv = new BoardVo();
bv.setBidx(rs.getInt("bidx"));
bv.setOriginbidx(rs.getInt("originbidx"));
bv.setDepth(rs.getInt("depth"));
bv.setLevel_(rs.getInt("level_"));
bv.setSubject(rs.getString("subject"));
bv.setContent(rs.getString("content"));
bv.setWriter(rs.getString("writer"));
bv.setWriteday(rs.getString("writeday"));
bv.setFilename(rs.getString("filename"));
bv.setHit(rs.getInt("hit"));
}
} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
rs.close();
pstmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return bv;
}
|
cs |
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
|
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="damain.BoardVo" %>
<%
BoardVo bv = (BoardVo) request.getAttribute("bv");
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
#btnList{
margin-right: 10px;
}
</style>
<!-- FONT AWE -->
<script src="https://kit.fontawesome.com/6c060c00b1.js" crossorigin="anonymous"></script>
<!-- BOOT STRAP -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
</head>
<body>
<body>
<div class="container" role="main" style="width: 700px;padding-top: 100px;">
<h2>게시판 내용</h2>
<div class="mb-3">
<!-- (날짜 :=bv.getWriteday().substring(0,10) %>) -->
<label for="title">제목</label>
<input type="text" class="form-control" name="subject" id="title" placeholder="제목을 입력해 주세요" value="<%=bv.getSubject()%>" readonly>
</div>
<div class="mb-3">
<label for="reg_id">작성자</label>
<input type="text" class="form-control" name="writer" id="reg_id" placeholder="이름을 입력해 주세요" value="<%=bv.getWriter()%>" readonly>
</div>
<div class="mb-3">
<label for="content">내용</label>
<textarea class="form-control" rows="15" name="content" id="content" placeholder="내용을 입력해 주세요" readonly ><%=bv.getContent()%></textarea>
</div>
<div class="mb-3">
<label for="content">다운로드 파일</label>
<img src = "<%=request.getContextPath()%>/images/<%=bv.getFilename()%>">
<a href="<%=request.getContextPath()%>/board/fileDownload.do?filename=<%=bv.getFilename()%>">
<%=bv.getFilename()%>
</a>
</div>
<div class="mb-3">
<label for="reg_id">조회수</label>
<input type="text" class="form-control" name="writer" id="reg_id" placeholder="이름을 입력해 주세요" value="<%=bv.getHit()%>" readonly>
</div>
<div style="justify-content: center;display: flex;float: right;">
<button type="button" class="btn btn-sm btn-primary" id="btnList" onclick="location.href='<%=request.getContextPath()%>/board/boardModify.do?bidx=<%=bv.getBidx() %>'">수정</button>
<button type="button" class="btn btn-sm btn-primary" id="btnList" onclick="location.href='<%=request.getContextPath()%>/board/boardDelete.do?bidx=<%=bv.getBidx()%>'">삭제</button>
<button type="button" class="btn btn-sm btn-primary" id="btnList" onclick="location.href='<%=request.getContextPath()%>/board/boardReply.do?bidx=<%=bv.getBidx()%>&originbidx=<%=bv.getOriginbidx()%>&depth=<%=bv.getDepth()%>&level_=<%=bv.getLevel_()%>'">답변</button>
<button type="button" class="btn btn-sm btn-primary" id="btnList" onclick="location.href='<%=request.getContextPath()%>/board/boardList.do'">목록</button>
</div>
</div>
</body>
</html>
</body>
</html>
|
cs |
'기존 > 🏀Jsp' 카테고리의 다른 글
[JSP] 게시판 삭제 구현하기 (0) | 2022.05.31 |
---|---|
[JSP] 게시판 수정 구현하기 (0) | 2022.05.31 |
[JSP] 게시판 리스트 구현하기 (0) | 2022.05.31 |
[JSP] 게시판 등록 구현하기 (0) | 2022.05.31 |
[게시판]게시판 컨트롤러 (0) | 2022.05.31 |