|
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76 |
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%--
JSP 내장객체
request ( 요청) - 매개변수 값을 얻어오는 것
response (응답)
out (웹에 출력함) - > ajax 에서 많이 씀.
session - 서버의 저장공간 forward(웹 이동 값을 같이 가지고 감)
application ( 몰라도 된다)
pageContext -> forward 는 여기 소속
config (몰라도 됨)
Servlet
request : HttpServletRequest
response : HttpServletResponse
--%>
<%
//내장 객체 : 동적할당을 하지 않고 사용할 수 있는 Object다
//인코딩을 맞출때 사용
request.setCharacterEncoding("utf-8");
//url 이 나온다고? 처음 실행하면 null 값만 나옴
//url에 값을 직접 넣어주는 작업
//http://localhost:8090/sample02/index.jsp 이렇게 하면 name=null 이 나옴 //http://localhost:8090/sample02/index.jsp?name=박진영 => 이렇게 치면 name 으로 값이 넘어 와서 출력이 name=박진영 나옴
String name = request.getParameter("name"); out.println("name = " + name);
out.println("<br>");
//http://localhost:8090/sample02/index.jsp?name=박진영&num=13 연달아서 값을 주려면 이렇게 & 주면됨 String num = request.getParameter("num");
out.println("num = " + num);
out.println("<br>");
//http://localhost:8090/sample02/index.jsp?name=박진영&num=13&hobby=사과&hobby=바나나&hobby=바비 -> 값 넘겨주기 url로
String strArr[] = request.getParameterValues("hobby");
if (strArr != null) {
for (int i = 0; i < strArr.length; i++) {
out.println("strArr[" + i + "] = " + strArr[i] + "<br>");
}
}
%>
</body>
</html>
==============================================================================
|
cs |
'JSP and Servlet' 카테고리의 다른 글
| JSP(4) getRequestDispatcher (0) | 2018.08.20 |
|---|---|
| JSP(3) (setAttribute,gettAttribute ),(sendRedirect, forward의 차이점) (0) | 2018.08.20 |
| JSP(1) <% %>jsp의 java 코드부,<%! %>선언부 , <%= %> 값 출력 (1) | 2018.08.17 |
| Servlet(10) attr , $.cookie("user_id"), prop("checked", false) ,removeCookie (좀더 보완해야 하는 곳) (0) | 2018.08.17 |
| Servlet(9) deleteCookie,addCookie (0) | 2018.08.16 |