-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathBookClubModify.jsp
More file actions
102 lines (91 loc) · 3.38 KB
/
BookClubModify.jsp
File metadata and controls
102 lines (91 loc) · 3.38 KB
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
<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="java.sql.*"%>
<%@page import="java.util.*"%>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>북클럽 게시판 수정</title>
<!-- 외부 CSS 적용 / 파일 경로 뒤에 ' ?v=1 ' 부분 지우지 마세요. 에러나요! -->
<!-- 단위 수정 잘못하면 UI랑 배열 깨집니다 -->
<link rel="stylesheet" type="text/css" href="Main.css?v=1">
<!-- jQuery 라이브러리 연결 -->
<script src="https://code.jquery.com/jquery-3.6.3.js"></script>
<script type="text/javascript">
function check() {
let frm = document.myform;
let postId = frm.postId;
let title = frm.title;
let content = frm.content;
if (title.value == "") {
alert("제목을 입력하세요");
myform.title.focus();
return false;
}
if (content.value == "") {
alert("내용을 입력하세요");
myform.content.focus();
return false;
} else {
frm.submit();
}
}
</script>
</head>
<body>
<%
// 인코딩
request.setCharacterEncoding("UTF-8");
// DB 연결
String DB_URL = "jdbc:mysql://localhost:3306/internetproject";
String DB_ID = "multi";
String DB_PASSWORD = "abcd";
Class.forName("com.mysql.cj.jdbc.Driver");
Connection con = DriverManager.getConnection(DB_URL, DB_ID, DB_PASSWORD);
String postId = request.getParameter("postId");
// postId가 null이거나 비어 있는지 확인
if (postId != null && !postId.isEmpty()) {
String jsql = "select * from clubpost where postId = ?";
PreparedStatement pstmt = con.prepareStatement(jsql);
pstmt.setInt(1, Integer.parseInt(postId));
ResultSet rs = pstmt.executeQuery();
if(rs.next()) {
String title = rs.getString("title");
String content = rs.getString("content").trim();
%>
<!-- header (로고) 북클럽 Ver. -->
<header>
<a href="BookClub.jsp?clubId=1">
<img src="images/LogoBC.jpg" style="width: 300px; height: 150px;" alt="북클럽 로고">
</a>
</header>
<main class="modifyBCMain">
<form method="post" action="BookClubModifyOk.jsp" name="myform">
<input type="hidden" name="postId" value="<%=postId%>">
<table>
<tr>
<th>제목</th>
<td><input type="text" name="title" value="<%=title%>" Maxlength="30" placeholder="제목을 입력하세요"></td>
</tr>
<tr>
<th>본문</th>
<td><textarea rows="15" cols="80" name="content"><%=content%></textarea></td>
</tr>
</table>
<button onclick="check()">수정</button>
<button class="Back"><a href="BookClubDetail.jsp?postId=<%=postId%>">취소</a></button>
</form>
</main>
<%
}
rs.close();
pstmt.close();
} else {
// postId가 null이거나 비어 있으면 처리할 내용 추가
// 예를 들어, 어떤 오류 메시지를 출력하거나, 다른 페이지로 리다이렉트할 수 있습니다.
}
con.close();
%>
</body>
</html>