19.04.29 페이지 내장객체, 페이지 디렉티브 (동영상 14강~16강)
Back-End/JSP 2019. 4. 29. 23:48-response-
웹 브라우저의 요청에 대한 응답 정보를 저장하고 있는 객체
-response.sendRedirect()-
어떤 결과를 처리해서 그 결과를 만족하면 다른페이지를 보여준다.
-예제 및 출력 결과-
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 |
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<center>
<h2>로그인 페이지</h2>
<form action="ResponseLoginProc.jsp" method="post">
<table width="400" border="1">
<tr height="60">
<td align="center" width="150">아이디</td>
<td align="Left" width="250"><input type="text" name="id">
</td>
</tr>
<tr height="60">
<td align="center" width="150">패스워드</td>
<td align="Left" width="250"><input type="password"
name="pass"></td>
</tr>
<tr height="60">
<td colspan="2" align="center"><input type="submit" name="전송">
</td>
</tr>
</table>
</form>
</center>
</body>
</html> |
cs |
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 |
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<%
request.setCharacterEncoding("EUC-KR");
//임의적으로 ID와 PASS를 설정
String dbid = "aaaa";
String dbpass = "1234";
//사용자로부터 넘어온 데이터를 입력 받아줌
String id = request.getParameter("id");
String pass = request.getParameter("pass");
if(dbid.equals(id) && dbpass.equals(pass))
{
//아이디와 패스워드가 일치 하니까 메인 페이지를 보여주어야 합니다.
response.sendRedirect("ResponseMain.jsp?id="+id);//넘어가는 페이지에 변수를 파라미터로 넘겨줄수있다.
}
else
{
%>
<script>
alert("아이디와 패스워드가 일치 하지 않습니다.");
history.go(-1);
</script>
<%
}
%>
</body>
</html> |
cs |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 |
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<%
request.setCharacterEncoding("EUC-KR"); //id값을 받아서 출력해야하므로 한글 문자셋을 설정한다.
%>
<h2><%=request.getParameter("id")%>님 반갑습니다.
</h2>
</body>
</html> |
cs |
-out-
jsp 페이지에서 생성된 결과를 브라우저에 출력할때 사용하는 객체
html에서 출력시 스크립트릿 <%= %>사용
-예제 및 출력 결과-
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 |
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Insert title here</title>
</head>
<body>
<%
String name = "알리미 어플";
%>
스크립트로 표현시
<%=name%>
이 화면에 출력
<p>
<%
out.println(name + "이 화면에 출력");
%>
</body>
</html> |
cs |
-session-
세션을 이용하여 데이터를 유지 및 전달할수 있다
자세한건 나중에 다룬다.
-예제 및 출력 결과-
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 |
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Insert title here</title>
</head>
<body>
<h2>세션 연습</h2>
<%
String name = "shin";
//세션을 이용하여 데이터를 유지 및 전달할수 있다
session.setAttribute("name1", name);//키를 기준으로 값을 기억한다. 오브젝트 타입이라 어떤타입이 와도 된다.
//세션 유지 시간
session.setMaxInactiveInterval(10); //10초가 세션의 유지시간
%>
<a href="SessionName.jsp?name=<%=name %>">세션 네임페이지로 이동</a>
</body>
</html> |
cs |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 |
<%@ page language="java" contentType="text/html; charset=EUC-KR"
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Insert title here</title>
</head>
<body>
<h2>세션 네임 페이지 입니다.</h2>
<%
String name = (String)session.getAttribute("name1"); //오브젝트 타입이기 때문에 String 타입으로 타입변환을 한다.
%>
<%=name %>님 반갑습니다.
<!-- 파라미터로 받을시에는 이 페이지에서 한번 읽은 값을 다른페이지에서 읽을수 없다 (다시 파라미터로 넘기지 않는한) -->
</body>
</html> |
cs |
-application-
웹 어플리케이션에 있는 자료를 전부 공유할 수 있게 해준다.
-Include 디렉티브-
여러페이지를 포함시켜서 한 페이지로 병합하는 것
여러개의 페이지가 각각 컴파일 되는 것이 아니라
한 페이지로 인식 및 변환 후 컴파일 한다.
-예제 및 출력 결과-
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 | <%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <!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=EUC-KR"> <title>Insert title here</title> </head> <body> <center> <table width="600" border="1"> <!-- Top 부분 --> <tr height="150"> <td width="600" align="center"><%@ include file="Top.jsp"%> <!-- Top.jsp 파일을 페이지 윗부분에 출력되도록 한다. --></td> </tr> <!-- Center 부분 --> <tr height="400"> <td width="600" align="center"><img alt="" src="img/a.jpg" width="400" height="300"> <!-- 이미지 파일을 출력시키고 크기를 정한다. --></td> </tr> <!-- Bottom --> <tr height="100"> <td width="600" align="center"><%@ include file="Bottom.jsp"%> <!-- Bottom.jsp 파일을 페이지 아랫부분에 출력되도록 한다. --></td> </tr> </table> </center> </body> </html> | cs |
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 | <%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%> <!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=EUC-KR"> <title>Insert title here</title> </head> <body> <div style="text-align: center;"> <!-- 가운데 정렬 --> <table width="600"> <tr height="100"> <td aglin="center" colspan="6"><font size="15">Camera 정보 사이트</font></td> </tr> <tr height="50"> <td align="center">캐논</td> <td align="center">니콘</td> <td align="center">삼성</td> <td align="center">소니</td> <td align="center">올림푸스</td> <td align="center">LG</td> </tr> </table> </div> <!-- 가운데 정렬 닫음--> </body> </html> | cs |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <%@ page language="java" contentType="text/html; charset=EUC-KR" 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> <div style="text-align: center;"> <table width="600"> <tr height="100"> <td aglin="center">회사 소개 : 서울 특별시 강서구 발산동 대주 @ 102동 <br> 전화번호 : 02-356-8989 </td> </tr> </table> </div> </body> </html> | cs |
'Back-End > JSP' 카테고리의 다른 글
a tag href 속성 (#, #none, 링크) 특징 (0) | 2019.04.30 |
---|---|
19.04.30 JSP 페이지 액션 태그 (동영상 17강~21강) (0) | 2019.04.30 |
19.04.29 JSP의 내장 객체 (0) | 2019.04.29 |
19.04.28 액션 태그 (0) | 2019.04.28 |
19.04.28 JSP의 지시자 (0) | 2019.04.28 |