기존의 view.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <%@ page import="java.sql.*"%> <% Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); String url = "jdbc:odbc:board2"; String id = ""; String pass = ""; int idx = Integer.parseInt(request.getParameter("idx")); int pg = Integer.parseInt(request.getParameter("pg")); try { Connection conn = DriverManager.getConnection(url,id,pass); Statement stmt = conn.createStatement(); String sql = "SELECT USERNAME, TITLE, MEMO, TIME, HIT FROM board1 WHERE NUM=" + idx; ResultSet rs = stmt.executeQuery(sql); if(rs.next()){ String name = rs.getString(1); String title = rs.getString(2); String memo = rs.getString(3); String time = rs.getString(4); int hit = rs.getInt(5); hit++; %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>게시판</title> </head> <body> <table> <tr> <td> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr style="background:url('img/table_mid.gif') repeat-x; text-align:center;"> <td width="5"><img src="img/table_left.gif" width="5" height="30" /></td> <td>내 용</td> <td width="5"><img src="img/table_right.gif" width="5" height="30" /></td> </tr> </table> <table width="413"> <tr> <td width="0"> </td> <td align="center" width="76">글번호</td> <td width="319"><%=idx%></td> <td width="0"> </td> </tr> <tr height="1" bgcolor="#dddddd"><td colspan="4" width="407"></td></tr> <tr> <td width="0"> </td> <td align="center" width="76">조회수</td> <td width="319"><%=hit%></td> <td width="0"> </td> </tr> <tr height="1" bgcolor="#dddddd"><td colspan="4" width="407"></td></tr> <tr> <td width="0"> </td> <td align="center" width="76">이름</td> <td width="319"><%=name%></td> <td width="0"> </td> </tr> <tr height="1" bgcolor="#dddddd"><td colspan="4" width="407"></td></tr> <tr> <td width="0"> </td> <td align="center" width="76">작성일</td> <td width="319"><%=time%></td> <td width="0"> </td> </tr> <tr height="1" bgcolor="#dddddd"><td colspan="4" width="407"></td></tr> <tr> <td width="0"> </td> <td align="center" width="76">제목</td> <td width="319"><%=title%></td> <td width="0"> </td> </tr> <tr height="1" bgcolor="#dddddd"><td colspan="4" width="407"></td></tr> <tr> <td width="0"></td> <td width="399" colspan="2" height="200"><%=memo %> </tr> <% sql = "UPDATE board1 SET HIT=" + hit + " where NUM=" +idx; stmt.executeUpdate(sql); rs.close(); stmt.close(); conn.close(); } }catch(SQLException e) { } %> <tr height="1" bgcolor="#dddddd"><td colspan="4" width="407"></td></tr> <tr height="1" bgcolor="#82B5DF"><td colspan="4" width="407"></td></tr> <tr align="center"> <td width="0"> </td> <td colspan="2" width="399"><input type=button value="글쓰기" OnClick="window.location='write.jsp'"> <input type=button value="답글" OnClick="window.location='reply.jsp?idx=<%=idx%>&pg=<%=pg%>'"> <input type=button value="목록" OnClick="window.location='list.jsp?pg=<%=pg%>'"> <input type=button value="수정" OnClick="window.location='modify.jsp?idx=<%=idx%>&pg=<%=pg%>'"> <input type=button value="삭제" OnClick="window.location='delete.jsp?idx=<%=idx%>&pg=<%=pg%>'"> <td width="0"> </td> </tr> </table> </td> </tr> </table> </body>
</html>
새로운 view.jsp
<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <%@ page import="board.*" %> <jsp:useBean id="dao" class="board.DAO"/> <% int idx = Integer.parseInt(request.getParameter("idx")); int pg = Integer.parseInt(request.getParameter("pg")); VO vo = dao.getView(idx); dao.UpdateHit(idx); %> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>게시판</title> </head> <body> <table> <tr> <td> <table width="100%" cellpadding="0" cellspacing="0" border="0"> <tr style="background:url('img/table_mid.gif') repeat-x; text-align:center;"> <td width="5"><img src="img/table_left.gif" width="5" height="30" /></td> <td>내 용</td> <td width="5"><img src="img/table_right.gif" width="5" height="30" /></td> </tr> </table> <table width="413"> <tr> <td width="0"> </td> <td align="center" width="76">글번호</td> <td width="319"><%=idx%></td> <td width="0"> </td> </tr> <tr height="1" bgcolor="#dddddd"><td colspan="4" width="407"></td></tr> <tr> <td width="0"> </td> <td align="center" width="76">조회수</td> <td width="319"><%=vo.getHit()%></td> <td width="0"> </td> </tr> <tr height="1" bgcolor="#dddddd"><td colspan="4" width="407"></td></tr> <tr> <td width="0"> </td> <td align="center" width="76">이름</td> <td width="319"><%=vo.getName()%></td> <td width="0"> </td> </tr> <tr height="1" bgcolor="#dddddd"><td colspan="4" width="407"></td></tr> <tr> <td width="0"> </td> <td align="center" width="76">작성일</td> <td width="319"><%=vo.getTime()%></td> <td width="0"> </td> </tr> <tr height="1" bgcolor="#dddddd"><td colspan="4" width="407"></td></tr> <tr> <td width="0"> </td> <td align="center" width="76">제목</td> <td width="319"><%=vo.getTitle()%></td> <td width="0"> </td> </tr> <tr height="1" bgcolor="#dddddd"><td colspan="4" width="407"></td></tr> <tr> <td width="0"></td> <td width="399" colspan="2" height="200"><%=vo.getMemo() %> </tr> <tr height="1" bgcolor="#dddddd"><td colspan="4" width="407"></td></tr> <tr height="1" bgcolor="#82B5DF"><td colspan="4" width="407"></td></tr> <tr align="center"> <td width="0"> </td> <td colspan="2" width="399"><input type=button value="글쓰기" OnClick="window.location='write.jsp'"> <input type=button value="답글" OnClick="window.location='reply.jsp?idx=<%=idx%>&pg=<%=pg%>'"> <input type=button value="목록" OnClick="window.location='list.jsp?pg=<%=pg%>'"> <input type=button value="수정" OnClick="window.location='modify.jsp?idx=<%=idx%>&pg=<%=pg%>'"> <input type=button value="삭제" OnClick="window.location='delete.jsp?idx=<%=idx%>&pg=<%=pg%>'"> <td width="0"> </td> </tr> </table> </td> </tr> </table> </body>
</html>
이상 없죠~?
이미지출처 : 판다의 이상한 블로그(http://ssppmm.tistory.com/)
'Programming > JSP - 게시판만들기' 카테고리의 다른 글
[JSP] JSP로 게시판 만들기[MODEL 1] - 11(글수정) (0) | 2013.01.25 |
---|---|
[JSP] JSP로 게시판 만들기[MODEL 1] - 10(글삭제) (3) | 2013.01.25 |
[JSP] JSP로 게시판 만들기[MODEL 1] - 7(글쓰기) (8) | 2013.01.25 |
[JSP] JSP로 게시판 만들기[MODEL 1] - 6(게시판 목록) (11) | 2013.01.25 |
[JSP] JSP로 게시판 만들기[MODEL 1] - 5(DAO.java) (15) | 2013.01.25 |