본문 바로가기
IT/JSP

[JSP] EL연습 02

by dya0 2019. 5. 20.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%
    pageContext.setAttribute("test""pageContext Test");
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>EL 내장 객체 사용 예제</title>
</head>
<body>
    page 영역의 값(test) : ${pageScope.test<br> 
    page 영역의 값 (test2) : ${pageScope.test2}<!-- 해당 속성이 없는 경우 출력 X -->
 </body>
</html>
Colored by Color Scripter

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%
    pageContext.setAttribute("test""pageContext Test");
    request.setAttribute("test""request Test");
    session.setAttribute("test""session Test");
    application.setAttribute("test""application Test");
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>EL 내장 객체 사용 예제</title>
</head>
<body>
    page 영역의 값: ${pageScope.test}<br>
    request 역역의 값 : ${requestScope.test}<br>
    session 영역의 값 : ${sessionScope.test}<br>
    application 영역의 값 : ${applicationScope.test<br>
    <!-- 해당 속성이 없는 경우 출력 X -->
</body>
</html>
Colored by Color Scripter

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
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%
    pageContext.setAttribute("test""pageContext Test");
    request.setAttribute("test""request Test");
    session.setAttribute("test""session Test");
    application.setAttribute("test""application Test");
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>EL 내장 객체 사용 예제</title>
</head>
<body>
<a href ="el_result.jsp" >내장객체를 이용한 EL 사용</a>
<a href ="el_result2.jsp" >속성을 이용한 EL 사용</a>
    <%-- 
    page 영역의 값: ${pageScope.test}<br>
    request 역역의 값 : ${requestScope.test}<br>
    session 영역의 값 : ${sessionScope.test}<br>
    application 영역의 값 : ${applicationScope.test<br> --%>
    <!-- 해당 속성이 없는 경우 출력 X -->
</body>
</html>
Colored by Color Scripter
 
 

el_result.jsp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%
    request.setCharacterEncoding("euc-kr");
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
    page 영역의 값: ${pageScope.test}<%--그 페이지 값이기 때문에 result의 값은 없다 따라서 안 나옴 --%>
    <br> 
    request 역역의 값 : ${requestScope.test}
    <br> 
    session 영역의 값 : ${sessionScope.test}
    <br> 
    application 영역의 값 : ${applicationScope.test}
    <br>
    <%--request에서는 id 안씀 충돌나서 session에서만 id사용 request는 id를 제외한 다른 건 사용함  --%>
    <%--dispatcher 방식으로 request 가져올 수 있음  --%>
</body>
</html>
Colored by Color Scripter
 

el_result2.jsp 결과

1
2
3
4
5
6
7
8
9
10
11
12
13
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
    <%request.setCharacterEncoding("euc-kr"); %>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>Insert title here</title>
</head>
<body>
${test}
</body>
</html>
 

페이지가 바뀌면 request랑 page값은 나오지 않음

request 값을 가져오고 싶으면 dispatcher 방식을 사용해야 한다.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<%
    pageContext.setAttribute("test""pageContext Test");
    request.setAttribute("test""request Test");
    session.setAttribute("test""session Test");
    application.setAttribute("test""application Test");
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="EUC-KR">
<title>EL 내장 객체 사용 예제</title>
</head>
<body>
<jsp:forward page = "el_result.jsp"/>
    <%-- 
    page 영역의 값: ${pageScope.test}<br>
    request 역역의 값 : ${requestScope.test}<br>
    session 영역의 값 : ${sessionScope.test}<br>
    application 영역의 값 : ${applicationScope.test<br> --%>
    <!-- 해당 속성이 없는 경우 출력 X -->
</body>
</html>
Colored by Color Scripter

'IT > JSP' 카테고리의 다른 글

[JSP] EL 03  (0) 2019.05.20
[JSP] EL 자바빈 사용  (0) 2019.05.20
[JSP] EL 연습 01  (0) 2019.05.20
[JSP] JSTL  (0) 2019.05.20
[JSP] 커넥션 풀을 이용한 페이지 제어 연습 02  (0) 2019.05.16