body의 데이터들을 한번에 전송하기 위해 from태그를 사용
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<h1>from 태그</h1>
<hr />
<!-- form -> 데이터 전송 -->
<!-- from action -> 데이터를 전송할 URL -->
<!-- method = get -> DB의 Select / query string -->
<!-- method = post -> DB의 Write -->
<form action="http://localhost:5500/ex04/6.html" method="get">
<!-- 사용자의 입력을 받아 정보를 전달하기 위해 사용 -->
<!-- name -> 키 value -> 값 (해쉬) -->
<!-- 텍스트입력 -->
<input type="text" name="fullname" value="홍길동" /><br />
<!-- GET 방식은 URL에 데이터가 노출되므로 비밀번호, 개인정보 전송에는 적합하지 않다 -->
<input type="password" name="pw" value="1234" /><br />
<input type="email" name="email" value="ssar@nate.com" /><br />
<!-- 체크박스 -->
<!-- 체크하지 않으면 value 자체를 날리지 않음 -->
<!-- 같은 name을 가진 checkbox는 서버에서 배열처럼 처리된다. -->
<input type="checkbox" name="ch1" value="1" />
<input type="checkbox" name="ch2" /><br />
<!-- 날짜 선택 -->
<input type="date" name="birthday" /><br />
<!-- 값 선택 -->
<select name="payday">
<option value="10">매월10일</option>
<option value="15">매월15일</option>
<option value="20">매월20일</option>
</select>
<!-- 버튼 -->
<!-- input:submit - value -> 버튼안의 이름 -->
<!-- submit: form 전송 button: 기본 동작 없음 (JS용) -->
<input type="submit" value="전송" />
</form>
</body>
</html>
checkbox를 체크하지 않았을 시 checkbox의 데이터를 전송하지 않음
form 태그는 데이터를 서버로 전송만 담당
DB 조회(Select)나 저장(Insert/Update)은 서버 로직에서 결정.

method = get 일때

http://localhost:5500/ex04/6.html <= URL
? <= ? 이후 부분을 쿼리스트링(문자열 질의) 이라 함
데이터 타입은 키=값 형식
& <= and
fullname=홍길동
&pw=1234
&email=ssar%40nate.com
&ch1=1
&ch2=on <= 체크박스에 value값을 설정하지 않으면 on이 넘어감(default)
&birthday=2026-01-05
&payday=10method = post 일때

동작 흐름
- 사용자가 form에 입력
- submit 클릭
- action URL로 HTTP 요청 전송
- method에 따라 GET/POST 결정
- 서버가 데이터를 처리
소켓 통신을 통해 실제 데이터 확인
package com.mtcoding; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; import java.net.ServerSocket; import java.net.Socket; import java.nio.charset.StandardCharsets; public class MyHttpServer { public static void main(String[] args) { try { ServerSocket ss = new ServerSocket(20000); Socket socket = ss.accept(); InputStream in = socket.getInputStream(); InputStreamReader ir = new InputStreamReader(in, StandardCharsets.UTF_8); BufferedReader br = new BufferedReader(ir); String line; int contentLength = 0; // 1) 헤더는 readLine()으로 읽는다 (빈 줄 나오면 헤더 끝) while ((line = br.readLine()) != null) { System.out.println("[server] " + line); if (line.toLowerCase().startsWith("content-length:")) { contentLength = Integer.parseInt(line.split(":")[1].trim()); } if (line.isEmpty()) break; // 헤더 끝 } // 2) 바디는 read()로 contentLength 만큼 읽는다 (이게 핵심!) char[] body = new char[contentLength]; int readTotal = 0; while (readTotal < contentLength) { int r = br.read(body, readTotal, contentLength - readTotal); if (r == -1) break; readTotal += r; } System.out.println("[server] ===== BODY ====="); System.out.println(new String(body, 0, readTotal)); System.out.println("[server] =============="); } catch (Exception e) { e.printStackTrace(); } } }
Get데이터
[server] GET /?fullname=kildong&pw=1234&email=ssar%40nate.com&ch1=1&ch2=on&birthday=2026-01-05&payday=10 HTTP/1.1 [server] Host: localhost:20000 [server] Connection: keep-alive [server] sec-ch-ua: "Google Chrome";v="143", "Chromium";v="143", "Not A(Brand";v="24" [server] sec-ch-ua-mobile: ?0 [server] sec-ch-ua-platform: "Windows" [server] Upgrade-Insecure-Requests: 1 [server] User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 [server] Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7 [server] Sec-Fetch-Site: cross-site [server] Sec-Fetch-Mode: navigate [server] Sec-Fetch-User: ?1 [server] Sec-Fetch-Dest: document [server] Referer: http://127.0.0.1:5500/ [server] Accept-Encoding: gzip, deflate, br, zstd [server] Accept-Language: ko,en;q=0.9 [server]
Post데이터
[server] POST / HTTP/1.1 [server] Host: localhost:20000 [server] Connection: keep-alive [server] Content-Length: 89 [server] Cache-Control: max-age=0 [server] sec-ch-ua: "Google Chrome";v="143", "Chromium";v="143", "Not A(Brand";v="24" [server] sec-ch-ua-mobile: ?0 [server] sec-ch-ua-platform: "Windows" [server] Origin: http://127.0.0.1:5500 [server] Content-Type: application/x-www-form-urlencoded [server] Upgrade-Insecure-Requests: 1 [server] User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 [server] Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7 [server] Sec-Fetch-Site: cross-site [server] Sec-Fetch-Mode: navigate [server] Sec-Fetch-User: ?1 [server] Sec-Fetch-Dest: document [server] Referer: http://127.0.0.1:5500/ [server] Accept-Encoding: gzip, deflate, br, zstd [server] Accept-Language: ko,en;q=0.9 [server] fullname=kildong&pw=1234&email=ssar%40nate.com&ch1=1&ch2=on&birthday=2026-01-05&payday=10





MIME 타입이란?
MIME 타입(Multipurpose Internet Mail Extensions)
"이 데이터가 무슨 종류의 데이터인지 알려주는 문자열"
즉,
브라우저 / 서버에게
"이건 HTML이야", "이건 이미지야", "이건 JSON이야"
라고 알려주는 데이터의 정체성 라벨
✅ MIME 타입 기본 구조
MIME 타입 | 설명데이터 | 예시 |
text/html | HTML 문서 | <html><body>hello</body></html> |
<br>text/plain | 단순 텍스트 | hello world |
application/json | JSON 데이터 | {"key": "value"} |
image/png | PNG 이미지 | 이미지 바이너리 |
image/jpeg | JPG 이미지 | 이미지 바이너리 |
multipart/form-data | 파일 업로드용 | 데이터파일 + 텍스트 혼합 |
application/octet-stream | 알 수 없는 바이너리 | 파일다운로드 처리 |
application/x-www-form-urlencoded | 기본 form 전송 형식 | key=value&key=value |
✅ 핵심 요약
MIME 타입은 “데이터의 정체성을 알려주는 라벨”이다브라우저와 서버는 MIME 타입을 보고👉 렌더링할지👉 JSON으로 파싱할지👉 다운로드할지를 결정한다.
✅ 실무에서 가장 많이 만나는 MIME 타입
- 웹 페이지 →
text/html
- REST API →
application/json
- 폼 전송(GET/POST) →
application/x-www-form-urlencoded
- 파일 업로드 →
multipart/form-data
Share article