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
|
else if (command.equals("/board/boardModify.do")) { //게시판 수정하기
System.out.println("���� ������");
//1.�Ķ���Ͱ� �Ѿ��
String bidx = request.getParameter("bidx");
int bidx_ = Integer.parseInt(bidx);
//2. ��
BoardDao bd = new BoardDao();
BoardVo bv = bd.boardSelectOne(bidx_);
request.setAttribute("bv", bv); //���������� �ڿ�����
//3.�̵���
RequestDispatcher rd = request.getRequestDispatcher("/board/boardModify.jsp");
rd.forward(request, response);
}else if (command.equals("/board/boardModifyAction.do")) {
String subject = request.getParameter("subject");
System.out.println("subject="+subject);
String content = request.getParameter("content");
System.out.println("content="+content);
String writer = request.getParameter("writer");
System.out.println("writer="+writer);
String bidx = request.getParameter("bidx");
System.out.println("bidx="+bidx);
int bidx_ = Integer.parseInt(bidx);
System.out.println("bidx_="+bidx_);
String ip = InetAddress.getLocalHost().getHostAddress();
HttpSession session = request.getSession();
int midx = (int)session.getAttribute("midx");
// int midx =3;
BoardDao bd = new BoardDao();
int value = bd.updateBoard(subject, content, writer, ip, midx,bidx_);
System.out.println(value);
if (value ==1) {
response.sendRedirect(request.getContextPath()+"/board/boardContent.do?bidx="+bidx);
}else {
response.sendRedirect(request.getContextPath()+"/board/boardModify.do?bidx="+bidx);
}
|
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
|
public int updateBoard(String subject,String content,String writer,String ip,int midx,int bidx) {
int value=0;
String sql="update board set subject=?, content=?, writer=?, ip=?, midx=?, writeday=sysdate where bidx=?";
try {
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, subject);
pstmt.setString(2, content);
pstmt.setString(3, writer);
pstmt.setString(4, ip);
pstmt.setInt(5, midx);
pstmt.setInt(6, bidx);
value= pstmt.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
}finally {
try {
pstmt.close();
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
return value;
}
|
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
|
<%@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");
if (session.getAttribute("memberId") == null){
out.println("<script>alert('로그인해주세요');location.href='"+request.getContextPath()+"/member/memberLogin.do'</script>");
}
%>
<!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>
<table>
<form method="post" action="<%=request.getContextPath()%>/board/boardModifyAction.do">
<input type="hidden" name="bidx" value="<%=bv.getBidx()%>">
<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() %>" >
</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()%>">
</div>
<div class="mb-3">
<label for="content">내용</label>
<textarea class="form-control" rows="15" name="content" id="content" placeholder="내용을 입력해 주세요" ><%=bv.getContent() %></textarea>
</div>
<div class="mb-3">
<label for="reg_id">파일</label>
<input type="file" class="form-control" name="file" id="reg_id" placeholder="이름을 입력해 주세요" value="<%=request.getContextPath()%>/board/fileDownload.do?filename=<%=bv.getFilename()%>">
</div>
<div style="justify-content: center;display: flex;float: right;">
<button type="submit" class="btn btn-sm btn-primary" id="btnList" >수정</button>
<button type="button" class="btn btn-sm btn-primary" id="btnList" onclick="location.href='<%=request.getContextPath()%>/board/boardList.do'">목록</button>
</div>
</div>
</form>
</table>
</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 |
[JSP] 게시판 등록 구현하기 (0) | 2022.05.31 |