`
topbox163
  • 浏览: 51901 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Struts iterator JSP Map 中嵌套 Map

阅读更多
见:附件:
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>


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics