본문 바로가기

Java

doGet(), doPost()

반응형

calculator.html

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<form action="calculator" method="post">
		<input type="submit" value="요청">
	</form>
</body>
</html>

 

 

 

calculator.java

package com.newlectrue.web;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/calculator")
public class Calculator extends HttpServlet {

//	@Override
//	protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
//
////		GET과 POST를 대문자로 입력해야함
//		if (req.getMethod().equals("GET")) {
//			System.out.println("GET 요청이 왔습니다");
//		} else if (req.getMethod().equals("POST")) {
//			System.out.println("POST 요청이 왔습니다.");
//		}
//
//		super.service(req, res);
//	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println("doPost()");
	}

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println("doGet()");
	}
}

 

 

https://youtu.be/arB7sQ9S7h0?list=PLq8wAnVUcTFVOtENMsujSgtv2TOsMy8zd 

 

반응형

'Java' 카테고리의 다른 글

jsp mvc model2  (0) 2021.09.03
JSP 내장 객체  (0) 2021.09.02
쿠키 메소드 - setPath(), setMaxAge()  (0) 2021.09.02
Cookie와 상태 관리  (0) 2021.09.02
Session 객체와 상태 관리  (0) 2021.09.02