ITeye博客

Struts iterator JSP Map 中嵌套 Map

topbox163 · 2010-05-18 16:20 · 企业架构 · Markdown

见:附件: 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+"/"; %>

<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">
-->

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。