---
title: "Struts iterator JSP Map 中嵌套 Map"
author: "topbox163"
date: "2010-05-18T16:20:22Z"
tags: []
categories: ["企业架构"]
slug: "struts-iterator-jsp-map-map"
draft: false
lastmod: "2010-05-18T16:20:22Z"
id: 669084
url: "https://topbox163.iteye.com/blog/669084"
---

见：附件:
package com.test.struts.action;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.interceptor.ServletRequestAware;

import com.opensymphony.xwork2.ActionSupport;


public class LoginAction extends ActionSupport  implements ServletRequestAware {
	
	private static final long serialVersionUID = -8657585481352290984L;
	private String uid;
	private String name;
	
	private HttpServletRequest request;
	
	
	public String getUid() {
		return uid;
	}
	public void setUid(String uid) {
		this.uid = uid;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String login(){
		String id = this.uid;
		String name = this.name;
		System.out.println("login");
		if(true)
			return 	SUCCESS;
		else
			return "loginError";
	}
	@Override
	public void validate() {
		System.out.println("id="+this.uid);
		System.out.println("name="+this.name);
	}
	public String mapInMap(){
		Map bigMap = new HashMap();		//外部MAP
		Map smallMap = new HashMap();	//内部MAP
		
		smallMap.put("ADD", "/add.jsp");
		smallMap.put("DELETE", "/DELETE.jsp");
		smallMap.put("UPDATE", "/UPDATE.jsp");
		smallMap.put("SELECT", "/SELECT.jsp");
		
		bigMap.put("PB", smallMap);
		
		request.setAttribute("bigMap", bigMap);
		return SUCCESS;
	}
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;
	}
	
}

mapInMap.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>MAP里嵌套MAP</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
  		<table>
  			<s:iterator value="#request.bigMap.keySet()" id="item">
  				<tr>
  					<td>外层MAP KEY=<s:property value="item"/></td>
  				</tr>
  				<s:iterator value="#request.bigMap.get(#item).keySet()" id="itemTwo">
  					<tr>
  						<td>内层MAP KEY=<s:property value="itemTwo"/></td>
  						<s:iterator value="#request.bigMap.get(#item).get(#itemTwo)" id="itemThree">
  							<td>
  								Value=<s:property value="itemThree"/>
  							</td>
  						</s:iterator>
  					</tr>
  				</s:iterator>
  			</s:iterator>
  		</table>
  </body>
</html>