메모 리스트
메모 제목에 A 태그 달기
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 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ page import="java.util.List"%> <%@ page import="memo.MemoDTO"%> <!DOCTYPE > <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <% String path=request.getContextPath(); //컨트롤러에서 넘어온 값을 읽어옴 // request.getAttribute(key) //object 타입이라 형변환 해야함 List<MemoDTO> items = (List<MemoDTO>) request.getAttribute("items"); %> <table border="1"> <tr> <th>번호</th> <th>이름</th> <th>메모</th> <th>날씨</th> </tr> <% for (MemoDTO dto : items) { %> <tr> <td><%=dto.getIdx()%></td> <td><%=dto.getWriter()%></td> <td> <a href="<%=path %>/memo_servlet/view.do?idx=<%=dto.getIdx() %>"> <%=dto.getMemo()%></a> </td> <td><%=dto.getPost_date()%></td> </tr> <% } %> </table> </body> </html> | cs |
2컨트롤러
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | else if(url.indexOf("view.do")!=-1){ //string 값으로 넘어온다. //글번호 int idx=Integer.parseInt(request.getParameter("idx")); //dao에 레코드 정보 조회 MemoDTO dto=dao.MemoView(idx); request.setAttribute("dto", dto); String page = "/memo/view.jsp"; RequestDispatcher rd=request.getRequestDispatcher(page); rd.forward(request, response); } } | cs |
3 다오
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 | // 게시글 상세 public MemoDTO MemoView(int idx) { Connection conn = null; PreparedStatement pstmt = null; ResultSet rs = null; MemoDTO dto = new MemoDTO(); try { conn = DB.dbConn(); String sql = "select * from memo where idx=?"; pstmt = conn.prepareStatement(sql); pstmt.setInt(1, idx); rs = pstmt.executeQuery(); if (rs.next()) { dto.setIdx(rs.getInt("idx")); dto.setMemo(rs.getString("memo")); dto.setWriter(rs.getString("writer")); dto.setPost_date(rs.getString("post_date")); } } catch (Exception e) { } finally {// resultset= > statement=> connection try { if (rs != null) { rs.close(); } } catch (Exception e2) { e2.printStackTrace(); } try { if (pstmt != null) { pstmt.close(); } } catch (Exception e2) { e2.printStackTrace(); } try { if (conn != null) { conn.close(); } } catch (Exception e2) { e2.printStackTrace(); } } return dto; } | cs 4. |
4. 상세 페이지
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 | <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE > <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <form name="form1" method="post"> <table border="1"> <tr> <td>날짜</td> <td>${dto.post_date}</td> </tr> <tr> <td>이름</td> <td><input name="writer" vlaue="${dto.writer}"> </td> </tr> <tr> <td>메모</td> <td><textarea name="memo"> ${dto.memo} </textarea></td> </tr> <tr> <td colspan="2" align="center"> <input type="button" value="수정" id="btnUpdate"> <input type="button" value="삭제" id="btnDelete"> </td> </tr> </table> </form> </body> </html> | cs |