프로젝트 구조 : 게시글의 상세내용을 보여줄 boardView.jsp 추가



이전강좌(0_2강좌) boardList.jsp파일 60번째라인에 제목 클릭시 boardView.jsp로 이동하는 링크추가

1
2
3
4
5
6
7
8
9
<tr>
    <td>
        <a href="<%=request.getContextPath()%>/board/boardView.jsp?boardNo=<%=listResultSet.getInt("board_no")%>">
            <%=listResultSet.getString("board_title")%>
        </a>
    </td>
    <td><%=listResultSet.getString("board_user")%></td>
    <td><%=listResultSet.getString("board_date")%></td>
</tr>
cs



boardView.jsp : boardList.jsp에서 board테이블의 PK값을 넘겨받아 게시글의 상세내용을 보여줄

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
<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>boardView</title>
</head>
<body>
<h1>BOARD VIEW</h1>
<%
if(request.getParameter("boardNo"== null) {
    response.sendRedirect(request.getContextPath()+"/board/boardList.jsp");
else {
    int boardNo = Integer.parseInt(request.getParameter("boardNo"));
    System.out.println("boardNo :"+boardNo);
    String dbUrl = "jdbc:mysql://127.0.0.1:3306/injava?useUnicode=true&characterEncoding=euckr";
    String dbUser = "root";
    String dbPw = "java0000";
    Connection connection = null;
    PreparedStatement statement = null;
    ResultSet resultSet = null;
    try {
        Class.forName("com.mysql.jdbc.Driver");
        connection = DriverManager.getConnection(dbUrl, dbUser, dbPw);
        String sql = "SELECT board_title, board_content, board_user, board_date FROM board WHERE board_no=?";
        statement = connection.prepareStatement(sql);
        statement.setInt(1, boardNo);
        resultSet = statement.executeQuery();
        if(resultSet.next()) {
%>
            <div>board_no :</div>
            <div><%=boardNo%></div>
            <div>board_title :</div>
            <div><%=resultSet.getString("board_title")%></div>
            <div>board_content :</div>
            <div><%=resultSet.getString("board_content")%></div>
            <div>board_user :</div>
            <div><%=resultSet.getString("board_user")%></div>
            <div>board_date :</div>
            <div><%=resultSet.getString("board_date")%></div>
            <div>
                <a href="">수정</a>
                <a href="">삭제</a>
            </div>
<%
        }
    } catch(Exception e) {
        e.printStackTrace();
        out.println("BOARD VIEW ERROR!");
    } finally {
        try {resultSet.close();} catch(Exception e){}
        try {statement.close();} catch(Exception e){}
        try {connection.close();} catch(Exception e){}
    }
}
%>
</body>
</html>
cs




+ Recent posts