240102 HTML Update.java

2024. 1. 4. 16:072023.11.21-2024.05.31

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
64
package com.sukgi.web;
 
import java.io.IOException;
import java.util.Map;
 
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import com.sukgi.dao.BoardDAO;
 
 
@WebServlet("/update")
public class Update extends HttpServlet {
    private static final long serialVersionUID = 1L;
       
  
    public Update() {
        super();
  
    }
 
    
    protected void doGet(HttpServletRequest request, HttpServletResponse response) 
throws ServletException, IOException {
    
        request.setCharacterEncoding("UTF-8");
        //DAO부르기
        BoardDAO dao = new BoardDAO();
        //날아오는 번호 잡기 ./update?no=10
        String no = request.getParameter("no");
        //데이터베이스에 질의해서 레코드 1개 가져오기
        Map<String, Object> detail = dao.detail(no);        
        //update.jsp 에게 돌려주기 = 페이지 이동
        //System.out.println(detail);
        //update.jsp에 값 보내기
        request.setAttribute("detail", detail);
        
        //jsp 부르기
        RequestDispatcher rd = request.getRequestDispatcher("update.jsp");
    
        rd.forward(request, response);
    }
 
    
    protected void doPost(HttpServletRequest request, HttpServletResponse response) 
throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        String title = request.getParameter("title");
        String no= request.getParameter("no");
        String content =  request.getParameter("content");
        
        
        BoardDAO dao = new BoardDAO();
        dao.update(no, title, content);
        
        response.sendRedirect("./detail.jsp?no="+no);
                
    
    }
 
}
 
cs

'2023.11.21-2024.05.31' 카테고리의 다른 글

240104 웹 만들기 ; index.html  (1) 2024.01.04
240102 웹 만들기 ; Write.java  (1) 2024.01.04
240102 웹 만들기 ; Test.java  (1) 2024.01.04
240102 HTML Study.java  (1) 2024.01.04
240102 HTML Delete.java  (1) 2024.01.04