웹페이지에서 데이터를 전송할 때 2가지 방식이 있다. get 방식과 post 방식이다.
<GET 방식>
- 입력한 데이터를 URL에 붙여서 전송한다. 데이터가 다 보이므로 보안에 취약하다.
- 전송할 수 있는 데이터는 256바이트를 넘을 수 없다.
- 전송속도는 POST방식 보다 빠르다.
<POST 방식>
- 입력한 데이터를 본문안에 포함해서 전송한다.
- 입력한 데이터가 URL에 보이지 않으므로 GET방식 보다 보안에 우수하다.
- 전송할 데이터의 길이에 제한이 없다.
- 복잡한 형태의 데이터를 전송할 때 유용하다.
<GET 방식 예제>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
</head>
<body>
<!-- get 방식을 사용해서 데이터 전송 (method="get") -->
이름 : <input type="text" name="name" size="10"><br>
주소 : <input type="text" name="address" size="30"><br>
취미 :
<input type="checkbox" name="hobby" value="game">게임
<input type="checkbox" name="hobby" value="travel">여행
<input type="checkbox" name="hobby" value="reading">독서
<br>
<input type="submit" value="전송">
</form>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
</head>
<body>
이름 : <%= request.getParameter("name") %><br>
주소 : <%= request.getParameter("address") %><br>
취미 :
<%
// 체크박스는 배열로 처리해야 한다.
String[] values = request.getParameterValues("hobby");
if(values != null){
%>
<%=values[i] %>
<%
}
}
%>
</body>
</html>
|
<POST 방식 예제>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%
// 인코딩
request.setCharacterEncoding("euc-kr");
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
</head>
<body>
<!-- post 방식을 사용해서 데이터 전송 (method="post") -->
이름 : <input type="text" name="name" size="10"><br>
주소 : <input type="text" name="address" size="30"><br>
취미 :
<input type="checkbox" name="hobby" value="game">게임
<input type="checkbox" name="hobby" value="travel">여행
<input type="checkbox" name="hobby" value="reading">독서
<br>
<input type="submit" value="전송">
</form>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<%
// 인코딩
request.setCharacterEncoding("euc-kr");
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
</head>
<body>
이름 : <%= request.getParameter("name") %><br>
주소 : <%= request.getParameter("address") %><br>
취미 :
<%
// 체크박스는 배열로 처리해야 한다.
String[] values = request.getParameterValues("hobby");
if(values != null){
%>
<%=values[i] %>
<%
}
}
%>
</body>
</html>
|
'IT기술 > JAVA' 카테고리의 다른 글
[JAVA] String to Date, Date to String 형변환 (0) | 2018.10.28 |
---|---|
execute / executeQuery / executeUpdate 차이 (0) | 2018.10.07 |
jsp 유효성 검사 (0) | 2018.10.06 |
jsp 넘어온 값(request) 확인 (0) | 2018.10.06 |
JSP 기본(내장) 객체 - 세션(session) (0) | 2017.03.24 |