728x90
1-3. 서블릿 클래스 Get, Post방식 전송
@WebServlet("/ch01/ex03/home/add")
public class DoGetPost extends HttpServlet {
private static final long serialVersionUID = 1L;
public void process(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>" + request.getMethod() + "</h2>");
out.printf("<p>%d+%d=%d</p>", num1,num2,num1+num2);
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
process(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
process(request, response);
}
}
/ch01/ex03/home/add.html
<!DOCTYPE html>
<html lang="ko">
<head>
<title>adder</title>
<meta charset="utf-8">
</head>
<body>
<form action="add" method="get">
<input type="submit" value="GET"/>
</form>
<form action="add" method="post">
<input type="submit" value="POST"/>
</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-02. 서블릿 클래스 POST 방식 (0) | 2017.11.01 |
[JSP] ch01-01. 서블릿 클래스 GET 방식 (0) | 2017.11.01 |
댓글