Struts iterator JSP Map 中嵌套 Map

本文介绍了一个使用Struts2框架实现的登录示例,重点展示了如何在Struts2 Action中创建并传递嵌套Map数据结构到前端页面进行展示。通过示例代码,读者可以了解到具体的实现细节,包括Map的构建方式及如何在JSP页面中使用Struts标签库进行迭代显示。
摘要由CSDN通过智能技术生成
见:附件:
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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值