반응형
Model 1 (기초)간략게시판 만들기..
기본적으로 오라클 DB와 연동해서 진행을 하였으며,
DB 테이블 구성은 게시판번호, 제목, 글쓴이, 시간, 내용 입니다.
JDK 1.8 버전
Ojdbc7 버전
list.jsp역할
- 데이터베이스에 저장되어 있는 글들을 불러와 목록으로 보여주는 부분이다.
- DB 로직에서 SQL 문을 통해 가져오는 데이터를 ResultSet rs 변수에 담고 rs변수를 활용한다.
- rs.getString("name명") 통해 데이터를 가져오도록 한다.
- 글 제목을 클릭했을 때 글 내용을 볼 수있는 content.jsp 이동하며 글번호(idx) 데이터를 함께 넘겨준다.
- 글 삭제를 클릭했을 때 글을 삭제하기 위한 delete.jsp 로 이동하며 똑같이 글 번호(idx) 데이터를 함께 넘겨준다.
idx 파라미터를 넘겨주는 이유는 content.jsp 및 delete.jsp 에서 글 번호에 해당하는 글을 확인하고 삭제하기 위해 필요하기 때문이다.
글번호(idx) 를 넘기기위해 URL에 파라미터를 넘기는 방식으로 URL 끝에 ? 추가하여 name=value 형식으로 추가되는 GET방식을 사용하였다.
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
|
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
</head>
<%
try{
String url = "jdbc:oracle:thin:@localhost:1521:XE";
String user = "dbuser";
String pwd = "dbpwd";
ResultSet rs = null;
Class.forName(DriverName);
Connection con = DriverManager.getConnection(url, user, pwd);
out.println("연결성공");
Statement stmt = con.createStatement();
String sql = "select * from BOARD2 ";
rs = stmt.executeQuery(sql);
%>
<body>
<h1>글목록</h1>
<table border="1">
<tr>
<th>번호</th>
<th>제목</th>
<th>작성자</th>
<th>날짜</th>
<th>내용</th>
</tr>
<%
while(rs.next()){
out.println("<tr><td>" + rs.getString("idx") + "</td>");
out.println("<td> <a href='content.jsp?idx=" +rs.getString("idx") + "'>" + rs.getString("title") + "</a></td>");
out.println("<td>" + rs.getString("writer") + "</td>");
out.println("<td>" + rs.getString("regdate") + "</td>");
out.println("<td>" + rs.getString("content") + "</td></tr>");
%>
</table>
<%
}
}catch(Exception e){
out.println(e.getMessage());
}
%>
</body>
</html>
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4f; text-decoration:none">Colored by Color Scripter
|
http://colorscripter.com/info#e" target="_blank" style="text-decoration:none; color:white">cs |
참고 - cocy님의 블로그 https://cusmaker.tistory.com/83
반응형
'JAVA' 카테고리의 다른 글
Model 1 간략한 게시판 만들기(delete.jsp) (0) | 2019.05.21 |
---|---|
Model 1 간략한 게시판 만들기(content.jsp) (0) | 2019.05.21 |
Model 1 간략한 게시판 만들기(writepro.jsp) (0) | 2019.05.21 |
Model 1 간략한 게시판 만들기(write.js) (0) | 2019.05.21 |
[JMS]Activemq 메시지 소비자(Consumer) (0) | 2019.02.18 |