WEB/JSP

[JSP] ch01-02. 서블릿 클래스 POST 방식

밍글링글링 2017. 11. 1.
728x90

1-2. 서블릿 클래스 Post방식 전송

@WebServlet("/ch01/ex02/add")
public class DoPost extends HttpServlet {
    private static final long serialVersionUID = 1L;
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        int num1 = 1;
        int num2 = 2;
        
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        out.println("<h2>POST</h2>");
        out.printf("<p>%d+%d=%d</p>", num1,num2,num1+num2);
}
 

 

/ch01/ex02/add.html

<!DOCTYPE html>
<html lang="ko">
<head>
<title>HTML</title>
<meta charset="utf-8">
</head>
<body>
    <form action="add" method="post">
        <input type="submit"/>
    </form>
</body>
</html>

 

 

728x90

'WEB > JSP' 카테고리의 다른 글

[JSP] ch02-02. declaration  (0) 2017.11.01
[JSP] ch02-01. scriptlet  (0) 2017.11.01
[JSP] ch01-04. LifeCycle  (0) 2017.11.01
[JSP] ch01-03. 서블릿 클래스 GET, POST 방식  (0) 2017.11.01
[JSP] ch01-01. 서블릿 클래스 GET 방식  (0) 2017.11.01

댓글