java

jsp- request๊ฐ์ฒด

dev_summer 2020. 10. 30. 17:01

 

* ์‹ค์Šต์˜ˆ์ œ

<%@page import="java.io.BufferedReader"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    
<%
	//http://localhost:8000/JspTest/requestComplet.jsp(URL์š”์ฒญ)
	
	// 1๋ฒˆ GET์š”์ฒญ์€ QueryString์„ ํ™•์ธ ํ•˜๋ฉด ๋œ๋‹ค. ํ•จ์ˆ˜ : getParameter()
	String id= request.getParameter("id");
	System.out.println("id:"+id);
	
	// 2๋ฒˆ POST์š”์ฒญ์€ ๋ฐ์ดํ„ฐ๋ฅผ Body(foerm date ๋“ฑ)์— ๋„ฃ์–ด์„œ ์ „์†กํ•œ๋‹ค.
	// ์ „์†ก ๋ฐฉ์‹์ด ๋„ˆ๋ฌด ๋งŽ์Œ: ์••์ถ•ํŒŒ์ผ , ๊ทธ๋ฆผํŒŒ์ผ, ๋™์˜์ƒ ํŒŒ์ผ, Form๋ฐ์ดํ„ฐ, 
	//                 Json๋ฐ์ดํ„ฐ, ๋ฌธ์ž์—ด, ๋ฐ”์ดํŠธ
	// ๊ทธ๋ž˜์„œ content type๊ฐ€ ํ•„์š”ํ•˜๋‹ค.
	// x-www-form-urlencode ํ•จ์ˆ˜ -> getparmeter();
	// ์ด์™ธ์˜ ๋ชจ๋“  ๋ฐ์ดํ„ฐ : getReader();
	// ์ ์ ˆํ•˜๊ฒŒ ํŒŒ์‹ฑ
	BufferedReader br=request.getReader();
	
	String line = null;
	while((line=br.readLine())!=null){
		System.out.println(line);
	}
	
	// 3๋ฒˆ header ํ™•์ธ
	String timer = request.getHeader("timer"); 
	System.out.println("timer : "+timer);
	
	if(timer !=null){
		System.out.print("์œ ํšจํ•œ ์ƒํƒœ");
	}else {
		System.out.print("์œ ํšจํ•˜์ง€์•Š์€ ์ƒํƒœ");
	}

%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>์•ผํ˜ธ</title>
</head>
<body>

</body>
</html>

 

 

 

 

* ํฌ์ŠคํŠธ๋งจ์„ ์ด์šฉํ•˜์—ฌ get, post๋ฐฉ์‹ ๋ฐ์ดํ„ฐ ํ™•์ธํ•˜๊ธฐ

 

 

 

get์š”์ฒญ์€ ?๋’ค์— ์ฟผ๋ฆฌ์ŠคํŠธ๋ง์œผ๋กœ ๋‚ ๋ฆฌ๊ณ  gerparmeter()๋กœ ๋ฐ›์„ ์ˆ˜ ์žˆ๋‹ค.

POST๋ฐฉ์‹ form์œผ๋กœ ์ฃผ๋ฉด getparmeter()๋กœ ๋ฐ›์„ ์ˆ˜ ์žˆ๋‹ค.

 

POST๋ฐฉ์‹ rowํƒ€์ž…์œผ๋กœ ๋„˜๊ฒจ์ฃผ์–ด๋„ id=seohaํ˜•์‹์ด๋ฉด ๋ฐ›์„ ์ˆ˜ ์žˆ๋‹ค.

 

heder ์ถ”๊ฐ€

 

 

'java' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

JSP - ๊ฐœ๋…์ •๋ฆฌ  (0) 2020.11.09
jsp - include  (0) 2020.10.30
jsp ๋‚ด์žฅ๊ฐ์ฒด ์ด์šฉํ•˜๊ธฐ  (0) 2020.10.30
jsp ๊ธฐ์ดˆ  (0) 2020.10.30
JSP ๊ธฐ๋ณธ๊ตฌ์กฐ  (0) 2020.10.30