java學習 jstl迴圈標籤展示List集合操作
阿新 • • 發佈:2019-01-26
上一篇講解的是運算元組操作,其實操作集合也差不太多:
1:List集合操作
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page import="com.mldn.wq.vo.SimpleInfo"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html >
<head>
<title>www.mldnjava.cn, MLDN高階Java培訓</title>
</head>
<body>
<%
List all = new ArrayList();
all.add("MLDN");
all.add("LiXingHua");
all.add("www.MLDN.cn");
pageContext.setAttribute("ref", all);
%>
<h3> 輸出全部:
<c:forEach items="${ref}" var="mem">
${mem}。
</c:forEach>
</h3>
</body>
</html>
2:Map集合操作
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ page import="com.mldn.wq.vo.SimpleInfo" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>www.mldnjava.cn, MLDN高階Java培訓</title>
</head>
<body>
<%
Map map = new HashMap();
map.put("mldn", "www.MLDNJAVA.cn");
map.put("lxh", "LiXingHua");
pageContext.setAttribute("ref", map);
%>
<c:forEach items="${ref}" var="mem">
<h3>${mem.key} --> ${mem.value}</h3>
</c:forEach>
</body>
</html>