프로젝트 구조 : 게시글의 상세내용을 보여줄 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 |
'P. 자바 미니 프로젝트 > jsp 게시판' 카테고리의 다른 글
P.1.5 JSP 게시판 만들기5 - 글수정 (0) | 2016.11.09 |
---|---|
P.1.4 JSP 게시판 만들기4 - 글삭제 (0) | 2016.11.09 |
P.1.2 JSP 게시판 만들기2 - 글목록 (0) | 2016.11.04 |
P.1.1 JSP 게시판 만들기1 - 글입력 (0) | 2016.11.04 |