用JSTL 迭代 Map

来源:互联网 发布:mysql默认端口3306 编辑:程序博客网 时间:2024/05/16 00:55
 <%@ page contentType="text/html; charset=gb2312" language="java" import="java.util.*" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<%!
 public static class TTT{
  private String name;
  public TTT(String name){
   this.name = name;
  }
  public String getName(){
   return name;
  }
 }
%>
<%
 Map map = new LinkedHashMap();
 map.put(new TTT("111"),"aaaaaa");
 map.put(new TTT("222"),"bbbbbb");
 request.setAttribute("map",map);
%>
<body>
<c:forEach items="${map}" var="item">
${item.key.name}-${item.value}<br/>
</c:forEach>
</body>
</html>
原创粉丝点击