๐ง์์ -1
๐hewon_map.jsp
<%@page import="java.util.HashMap"%>
<%@page import="java.util.Map"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
Map<String, String> hewonMap=new HashMap<String, String>();
hewonMap.put("first.name", "ํ");
hewonMap.put("second.name", "๊ธธ๋");
//
request.setAttribute("hewonMap", hewonMap);
//
request.getRequestDispatcher("hewon_map_el.jsp").forward(request, response);
%>
๐hewon_map_el.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>MVC</title>
</head>
<body>
<h1>EL - Map</h1>
<hr>
<%-- ์ค์ฝํ ์์ฑ๊ฐ์ผ๋ก Map ๊ฐ์ฒด๊ฐ ์ ์ฅ๋ ๊ฒฝ์ฐ ๋งตํค์ EL ํํ์์ผ๋ก ์ฌ์ฉํ๊ธฐ ๋ถ์ ์ ํ ๋ฌธ์๊ฐ ์กด์ฌํ ๊ฒฝ์ฐ . ์ฐ์ฐ์๋ก ๋งตํค๋ฅผ ํํํ์ฌ ๋งต๊ฐ์ ์ ๊ณต๋ฐ์ ์ถ๋ ฅ ๋ถ๊ฐ๋ฅ --%>
<%-- <p>์ด๋ฆ = ${hewonMap.first.name } ${hewonMap.second.name }</p> --%>
<%-- --%>
<%-- ์ค์ฝํ ์์ฑ๊ฐ์ผ๋ก Map ๊ฐ์ฒด๊ฐ ์ ์ฅ๋ ๊ฒฝ์ฐ ๋งตํค์ EL ํํ์์ผ๋ก ์ฌ์ฉํ๊ธฐ ๋ถ์ ์ ํ ๋ฌธ์๊ฐ ์กด์ฌํ ๊ฒฝ์ฐ [] ์ฐ์ฐ์๋ก ๋งตํค๋ฅผ ํํํ์ฌ ๋งต๊ฐ์ ์ ๊ณต๋ฐ์ ์ถ๋ ฅ --%>
<p>์ด๋ฆ = ${hewonMap["first.name"] } ${hewonMap["second.name"] }</p>
</body>
</html>
๐ง์์ -2
๐fruits_map.jsp
<%@page import="java.util.HashMap"%>
<%@page import="java.util.Map"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%
Map<String, String> fruitsMap=new HashMap<String, String>();
fruitsMap.put("one", "๋ธ๊ธฐ");
fruitsMap.put("two", "๋ณต์ญ์");
fruitsMap.put("three", "์ฌ๊ณผ");
//
request.setAttribute("fruitsMap", fruitsMap);
request.setAttribute("choice", "two");
//
request.getRequestDispatcher("fruits_map_el.jsp").forward(request, response);
%>
๐fruits_map_el.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>MVC</title>
</head>
<body>
<h1>EL - Map</h1>
<hr>
<p>๊ณผ์ผ-1 = ${fruitsMap.one }</p>
<p>๊ณผ์ผ-2 = ${fruitsMap.two }</p>
<p>๊ณผ์ผ-3 = ${fruitsMap.three }</p>
<hr>
<p>์ข์ํ๋ ๊ณผ์ผ = ${fruitsMap.two }</p>
<p>์ข์ํ๋ ๊ณผ์ผ = ${fruitsMap["two"] }</p>
<%-- ์ค์ฝํ ์์ฑ๊ฐ์ด Map ๊ฐ์ฒด์ธ ๊ฒฝ์ฐ ๋งตํค๋ฅผ ์ด์ฉํ์ฌ ๋งต๊ฐ์ ์ ๊ณต๋ฐ์ ์ถ๋ ฅ ๊ฐ๋ฅ --%>
<%-- โ ๋งตํค์ ํด๋นํ๋ ๋งต๊ฐ์ด ์๋ ๊ฒฝ์ฐ EL ๋ฏธ์คํ --%>
<%-- <p>์ข์ํ๋ ๊ณผ์ผ = ${fruitsMap.choice }</p> --%>
<%-- EL ํํ์์์ [] ์ฐ์ฐ์๋ฅผ ์ด์ฉํ์ฌ ๋ค๋ฅธ ์ค์ฝํ ์์ฑ๊ฐ์ ์ ๊ณต๋ฐ์ ๋งตํค๋ก ํํํ์ฌ ๋งต๊ฐ ์ถ๋ ฅ ๊ฐ๋ฅ --%>
<p>์ข์ํ๋ ๊ณผ์ผ = ${fruitsMap[choice] }</p>
</body>
</html>