forked from zeroday7/JavaWebProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathel02.jsp
More file actions
162 lines (143 loc) · 3.57 KB
/
Copy pathel02.jsp
File metadata and controls
162 lines (143 loc) · 3.57 KB
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
<%@page import="java.util.ListResourceBundle"%>
<%@page import="java.util.ResourceBundle"%>
<%@page import="spms.vo.Member"%>
<%@page import="java.util.HashMap"%>
<%@page import="java.util.Map"%>
<%@page import="java.util.List"%>
<%@page import="java.util.LinkedList"%>
<%@ 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>EL(Expression Language)</title>
<style type="text/css">
body {
font-size: small;
}
table {
border: thin solid gray;
border-collapse: collapse;
}
td, th {
border: thin dotted gray;
padding: 2px;
}
th {
background-color: lightgray;
}
pre {
font-size: 90%;
}
</style>
</head>
<body>
<p><a href="el01.jsp">[이전]</a><a href="el03.jsp">[다음]</a></p>
<h2>EL - 값 꺼내기</h2>
<%
// 데이터 준비
pageContext.setAttribute("scores", new int[]{90,80,70,100});
List<String> nameList = new LinkedList<String>();
nameList.add("홍길동");
nameList.add("임꺽정");
nameList.add("일지매");
pageContext.setAttribute("nameList", nameList);
Map<String,String> map = new HashMap<String,String>();
map.put("s01", "홍길동");
map.put("s02", "임꺽정");
map.put("s03", "일지매");
pageContext.setAttribute("map", map);
pageContext.setAttribute("member",
new Member()
.setNo(100)
.setName("홍길동")
.setEmail("[email protected]"));
pageContext.setAttribute("myRB",
ResourceBundle.getBundle("MyResourceBundle"));
%>
<table>
<tr><th>대상</th><th>EL 코드</th><th>설명</th></tr>
<tr>
<td>배열</td><td>\${myArray[1]}</td>
<td>배열에서 해당 인덱스의 값을 꺼낸다.<br>
<pre>
[자바 코드]
pageContext.setAttribute("scores", new int[]{90,80,70,100});
[실행 결과]
\${scores[2]} = ${scores[2]}
</pre>
</td>
</tr>
<tr>
<td>리스트</td><td>\${myList[2]}</td>
<td>List 객체에서 인덱스로 지정된 항목의 값을 꺼낸다.
<pre>
[자바 코드]
List nameList = new LinkedList();
nameList.add("홍길동");
nameList.add("임꺽정");
nameList.add("일지매");
pageContext.setAttribute("nameList", nameList);
[실행 결과]
\${nameList[1]} = ${nameList[1]}
</pre>
</td>
</tr>
<tr>
<td>맵</td><td>\${myMap.keyName}</td>
<td>Map 객체에서 키에 해당하는 값을 꺼낸다.
<pre>
[자바 코드]
Map map = new HashMap();
map.put("s01", "홍길동");
map.put("s02", "임꺽정");
map.put("s03", "일지매");
pageContext.setAttribute("map", map);
[실행 결과]
\${map.s02} = ${map.s02}
</pre>
</td>
</tr>
<tr>
<td>자바빈</td><td>\${myObj.propName}</td>
<td>자바 객체에서 프로퍼티의 값을 꺼낸다.
<pre>
[자바 코드]
pageContext.setAttribute("member",
new Member()
.setNo(100)
.setName("홍길동")
.setEmail("[email protected]"));
[실행 결과]
\${member.email} = ${member.email}
</pre>
</td>
</tr>
<tr>
<td>리소스 번들</td><td>\${myRB.keyName}</td>
<td>ResourceBundle 객체에서 키에 해당하는 값을 꺼낸다.
<pre>
[자바 코드]
import java.util.ListResourceBundle;
public class MyResourceBundle_ko_KR extends ListResourceBundle {
public Object[][] getContents() {
return new Object[][] {
{"OK", "확인"},
{"Cancel", "취소"},
{"Reset", "재설정"},
{"Submit", "제출"}
};
}
}
pageContext.setAttribute("myRB",
ResourceBundle.getBundle("MyResourceBundle"));
[실행 결과]
\${myRB.OK} = ${myRB.OK}
</pre>
</td>
</tr>
</table>
<p><a href="el01.jsp">[이전]</a><a href="el03.jsp">[다음]</a></p>
</body>
</html>