본문 바로가기

웹 프로그래밍/Servlet

[Servlet] doGet VS doPost 차이

doGet : ? 뒤에 요청하는 정보를 담아서 보낸다. 즉, url에 정보를 담아 보낸다. 방대한 양을 보내긴 어렵다. 정보가 보이기 때문에 보안에도 안좋다.

=> name=value 형태로 날라가는 형태.

 

doPost : body에 내용을 담아서 보낸다. form 태그 방식으로만 보낼 수 있다. form 태그 내에 메소드 속성을 post라고 하면 된다. 

 

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<!-- http:/localhost:9999/Lecture-WEB/method -->
	
	<a href = "/Lecture-WEB/method">요청 </a> <!-- /Lecture-WEB은 왜 써주는거야? -->
	
	<form action = "/Lecture-WEB/method" method = "get">
		ID : <input type = "text" name = "id"> <!-- name이라는 속성을 써줘야 query문에 담겨 간다. method?id=2060340009 -->
		<input type = "submit" value = "GET방식 호출">
	</form>
	
	<form action = "/Lecture-WEB/method" method = "post">
		ID : <input type = "text" name = "id">
		<input type = "submit" value = "post 방식 호출">
	</form>

</body>
</html>

'웹 프로그래밍 > Servlet' 카테고리의 다른 글

[Servlet] 기초(2)  (0) 2020.06.25