Jsp - request,response

2020. 6. 27. 20:48Jsp

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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>jsp1/application.jsp</h1>
<%
//application내장객체-웹컨테이너 제공하는 객체
//                                        -웹애플리케이션 서버의 정보, 자원을 저장
//                                         웹애플리케이션 서버하나 객체 생성
//                                         웹애플리케이션 서버 자원하나 공유(방문자수,통계,...)
//                                         서버start 생성, 서버stop 사라짐
 
%>
서버정보 : <%=application.getServerInfo() %><br>
파일정보 : <%=application.getMimeType("test1.html"%><br>
<%
//첨부파일 형인식
//getServletContext().getMimeType(sFilePath);
%>
물리적인 경로 : <%=application.getRealPath("/"%>
<%
//p192    pageContext : 현페이지 정보 저장하는 내장객체
//                                      : 페이지가 바뀌면 저장되는 값도 변경
%>
현페이지 세션값 : <%=pageContext.getSession() %><br>
현페이지 ServletContext : <%=pageContext.getServletContext() %><br>
<%
//p201    out내장객체
out.println("출력내장객체");
%>
출력 버퍼(기억장소) 크기 : <%=out.getBufferSize() %>바이트<br>
사용하고 남은 기억장소 크기 : <%=out.getRemaining() %>바이트<br>
<%
//기억장소를 닫기
out.close();
out.println("다시출력");
//config 설정내장객체, page,exception 내장객체,....
 
%>
</body>
</html>
 
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>Jsp1/for.jsp</h1>
<%
String[] hobby2=new String[3];
hobby2[0]="여행";
hobby2[1]="게임";
hobby2[2]="독서";
        
String[] hobby3=new String[]{"여행","게임","독서"};
String[] hobby={"여행","게임","독서"};
 
 
for(int i=0;i<hobby.length;i++){
    
    out.println(hobby[i]+"<br>");
    
    
}
 
 
for(int i=0;i<hobby.length;i++){
    %>
    <%=hobby[i]  %><br>
    <%
}
 
%>
<table border="1">
<tr><td>번호</td><td>취미</td></tr>
<tr><td>1</td><td>여행</td></tr>
<tr><td>2</td><td>게임</td></tr>
<tr><td>3</td><td>독서</td></tr>
</table>
 
<table border="1">
<tr><td>번호</td><td>취미</td></tr>
<%
for(int i=0;i<hobby.length;i++){
    %>
    <tr><td><%=i+1  %></td><td><%=hobby[i]  %></td></tr>
    <%
}
%>
</table>
 
 
</body>
</html>
 
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ include file="colorset.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body bgcolor="<%=col1%>">
<h1>jsp1/include.jsp</h1>
<table border="1" width="600" height="600">
<tr><td colspan="2" height="100"><jsp:include page="top.jsp"/></td></tr>
<tr><td width="100"><jsp:include page="left.jsp"/></td><td>본문</td></tr>
<tr><td colspan="2" height="100"><jsp:include page="bottom.jsp"/></td></tr>
</table>
</body>
</html>
 
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>jsp/request.jsp</h1>
서버 : <%=request.getServerName() %><br>
서버포트번호 : <%=request.getServerPort() %><br>
요청주소 : <%=request.getRequestURL() %><br>
요청URI주소 : <%=request.getRequestURI() %><br>
프로토콜 : <%=request.getProtocol() %><br>
요청방식 : <%=request.getMethod() %><br>
사용자IP주소 : <%=request.getRemoteAddr() %><br>
서버애플리케이션(컨텍스트)경로 : <%=request.getContextPath() %><br>
서버물리적인 경로 : <%=request.getRealPath("/"%><br>
<!-- "/"는 roote이다 -->
http헤더정보 : <%=request.getHeader("accept-language"%><br>
http헤더정보 : <%=request.getHeader("user-agent"%><br>
http헤더정보 : <%=request.getHeader("connection"%><br>
 
</body>
</html>
 
 
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>jsp1/response.jsp</h1>
<%
//서버에서 처리한 결과를 클라이언트에 응답할때 http header값 변경
//response.setHeader("헤더이름","값");
//서버에서 클라이언트에 보낼때 파일을 브라우저에서 바로 실행하지 않고 첨부(다운)되게 설정
//response.setHeader("Content-Deisposition","attachment; filename=")
 
//서버에서 처리한 결과를 보내는 타입을 설정해서 보내기
//response.setContentType("text/html; charset=UTF-8");
 
//쿠키값을 서버에서 클라이언트로 보낼때 
//response.addCookie(쿠키);
 
//서버에서 클라이언트 응답할때 다른 페이지요청을 재전송
//html태그<a href="request.jsp">하이퍼링크</a>
//자바스크립트 location.href="request.jsp"
//jsp 하이퍼링크
response.sendRedirect("requeset.jsp");
%>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>jsp1/scopeForm.jsp</h1>
<%
// 영역                                영역내장객체                                유효범위
// page                            pageContext                            해당 페이지에서만
// request                        request                                        클라이언트(사용자)의 요청이 있는동안만
// session                        session                                        클라이언트(사용자)가 서버에 연결되있는 동안만
// application                application                                웹애플리케이션이 실행되고 있는 동안
 
//내장객체에 값 저장가능                내장객체.setAttribute(키이름,값)                    내장객체안에 키이름으로 값저장
//내장객체 값 가져오기                 내장객체.getAttribute(키이름)                        내장객체안에 키이름에 해당하는 값
 
%>
<form action="scopePro.jsp" method="get">
아이디 : <input type="text" name="id"><br>
비밀번호 : <input type="password" name="pa"><br>
<input type="submit" value="전송">
 
 
 
</form>
 
 
</body>
</html>
 
 
<%@page import="com.sun.corba.se.impl.oa.poa.AOMEntry"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>jsp1/scopePro.jsp</h1>
<%
// 변수=request에 저장된 파라미터 "id"가져오기
String id=request.getParameter("id");
String pa=request.getParameter("pa");
// 내장객체 값 저장 
pageContext.setAttribute("page","pageContext  value");// (페이지이름,페이지 값);
//해당 페이지 값저장
request.setAttribute("req","request value");//(이름,값);
//사용자의 요청 값저장
session.setAttribute("ses","session value");
//연결정보를 저장하는 session 기억장소에 값 저장
application.setAttribute("app","application value");
// 웹애플리케이션이 실행되고 있는 동안(웹서버 start 되는동안) 값 저장
%>
아이디 : <%=id %><br>
비밀번호 : <%=pa %><br>
pageContext저장된값 : <%=pageContext.getAttribute("page"%><br>
request저장된값 : <%=request.getAttribute("req"%><br>
session저장된값 : <%=session.getAttribute("ses"%><br>
application저장된값 : <%=application.getAttribute("app"%><br>
<!-- http://localhost:8080/Study_JSP/Jsp1/scopePro.jsp?id=sdfe &pa=q21123-->
<a href="scopeProPro.jsp">scopeProPro.jsp이동</a><!-- 이동태그 -->
<a href="scopeProPro.jsp?id=<%=id%>&pa=<%=pa%>">scopeProPro.jsp이동</a><!-- 이동태그 -->
 
<script type="text/javascript">
// alert("scopeProPro.jsp이동");
<%-- location.href="scopeProPro.jsp?id=<%=id%>&pa=<%=pa%>"//버튼을 눌리지 않아도 바로 지정 페이지로 이동!!!!!!!!!, 스크립트 이동!!!!!!,메세지창 띄우고 할때 사용. --%>
</script>
<%-- <% response.sendRedirect("scopeProPro.jsp?id="+id+"&pa="+pa);  %> --%>
<%--//jsp 이동방법. 이동방법중 제일 먼저 이동가능.퍼센트표시 안에 것들이 먼저 처리되기 때문. %안에는 %출력문을 사용할수 없기때문에 "문자열 +변수"로 선언해야함--%>
<%
//액션태그 :   태그처럼 사용할수있는 jsp문법
//forward액션태그 : 페이지 이동
//                                     1.Pro.jsp에서 ProPro.jsp로 이동
//                                     주소줄에 Pro.jsp이 보이고 실행화면에는 ProPro.jsp
//                                     2.Pro.jsp에 있는 request값 을 모두 들고 ProPro.jsp 로 이동함
%>
<jsp:forward page="scopeProPro.jsp"/>
</body>
</html>
 
 
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
 
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>jsp1/scopeProPro.jsp</h1>
<%
// 변수=request에 저장된 파라미터 "id"가져오기
String id=request.getParameter("id");
String pa=request.getParameter("pa");
 
%>
아이디 : <%=id %><br>
비밀번호 : <%=pa %><br>
pageContext저장된값 : <%=pageContext.getAttribute("page"%><br>
request저장된값 : <%=request.getAttribute("req"%><br>
session저장된값 : <%=session.getAttribute("ses"%><br>
application저장된값 : <%=application.getAttribute("app"%><br>
 
</body>
</html>
 
 
cs

 

저번에 배웠던 화면 제어와 함수 for 문을 활용한 화면에 정보 뿌리기, 그리고 request와 response에서 사용되는

명령어들을 배워보았고 배경색을 지정하고 화면제어를 통해 다른 페이지에 저장해 놓은 내용을 한 화면에 구역을 나눠서 표시해보는 것도 배워 보았다. 갑자기 처음에 html로 배우다 이클립스로 여러 명령어들을 사용하며 배우다 보니

확 어려워진 것 같지만 연산과정같은건 생각할 필요 없이 필요한 곳에 명령어들만 불러와서 표현할 수 있는 것은 매력적으로 다가왔다. 

'Jsp' 카테고리의 다른 글

Jsp - cookie  (0) 2020.06.27
Jsp - session  (0) 2020.06.27
Jsp - 회원가입전송  (0) 2020.06.17
Jsp - 회원가입창  (0) 2020.06.16
Jsp - 버튼제어3  (0) 2020.06.16