---
title: "[基础]Map在JSP中的两种显示方式"
author: "uule"
date: "2011-10-27T09:36:16Z"
tags: []
categories: ["Web前端"]
slug: "map-jsp"
draft: false
lastmod: "2011-10-27T09:36:16Z"
id: 1217978
url: "https://uule.iteye.com/blog/1217978"
---

1、

Java：

```
  for(EglSpecialRequest req : list){
			for(String idStr : ids){
				if(StringUtils.isEmpty(idStr)) continue;
				Integer id = Integer.parseInt(idStr);
				if(id - req.getId() == 0){
					idsMap.put(req.getId(), req.getRequestNameEn());
				}
			}
		}
		return idsMap;

	bookingHotelForm.set("idsMap", idsMap);
```

 JSP：

```
  <c:forEach items="${SPECIAL_REQUEST_LIST}" var="req">
							<c:set value="${req.id}" var="key"/>				
							<c:if test="${req.type == '3'}">
								${empty bookingHotelForm.map.idsMap[key] ? "" : bookingHotelForm.map.idsMap[key]}
								${empty bookingHotelForm.map.timeDateMap[key] ? "" : bookingHotelForm.map.timeDateMap[key]}
								<c:if test="${!empty bookingHotelForm.map.idsMap[key]}"><br><br></c:if>
							</c:if>
						</c:forEach>
```

 

2、

Form：

```
   <form-property name="testMap" type="java.util.Map" />
```

Java：

```
 Map<String, String> testMap  = new HashMap<String, String>();
 for (int i = 0; i < packageMiscellaneousList.size(); i++) {
				PackageMiscellaneous packageMiscellaneous = packageMiscellaneousList.get(i);
				supplierCode.put(i+"", packageMiscellaneous.getSupplierCode());
				testMap.put(i+"", "TestNo"+i);
			}

			packageMiscellaneousForm.set("testMap", testMap );
```

 JSP：

```
 <c:forEach items="${packageMiscellaneousForm.map.testMap}" var="item" varStatus="i">
					<tr>	
						<td>
							<html:select property="supplierCode(${i.index})" styleId="supplierCode_${i.index}">
								<html:option value="">--Please select supplier--</html:option>
								<c:forEach items="${SUPPLIER_LIST}" var="supplier">
									<html:option value="${supplier.suppliercode}">
										${supplier.suppliername }
									</html:option>
								</c:forEach>
							</html:select>
							
						</td>						
						<td>
							<html:text property="testMap(${i.index})" styleId="testMap_${i.index}"></html:text>
						</td>
					</tr>
					</c:forEach>
```

 。。。