怎么在Struts2中利用OGNL表达式对地图进行遍历

  介绍

这篇文章给大家介绍怎么在Struts2中利用OGNL表达式对地图进行遍历,内容非常详细,感兴趣的小伙伴们可以参考借鉴,希望对大家能有所帮助。

一.Action中的代码:MapAction。java

包com.zx.demo.action;   进口java.util.ArrayList;   进口java.util.HashMap;   进口并不知道;   进口java.util.Map;   进口com.opensymphony.xwork2.ActionSupport;   进口com.zx.demo.model.Product;   进口com.zx.demo.model.Student;   公共类MapAction ActionSupport延伸   {   私人Map<字符串,String>地图;   私人Map<字符串,Student>studentMap;   私人Map比;listMap;//这里省略预备方法   公共字符串testMap () {   地图=new HashMap<字符串,String> ();   map.put(“1”,“人的);   map.put (“2“,“two");   studentMap=new HashMap<字符串,Student> ();   studentMap.put (“student1"新学生(新长(1)、“20034140201”、“张三1“,“男”,25));   studentMap.put (“student2"新学生(新长(2)、“20034140202”、“张三2“,“女“,26));   studentMap.put (“student3"新学生(新长(3)、“20034140202”、“张三3“,“男”,27));   arrayMap=new HashMap在();   Listlist1=new ArrayList ();   。add(新学生(新长(1),“20034140201“,“张三1“,“男”,25));   。add(新学生(新长(2),“20034140202“,“张三2“,“男”,25));   。add(新学生(新长(3),“20034140203“,“张三3“,“男”,25));   listMap.put (“class1" list1);   List用于=new ArrayList ();   用于。add(新学生(新长(1),“20034140301“,“李四1“,“男”,20));   用于。add(新学生(新长(2),“20034140302“,“李四2“,“男”,21));   用于。add(新学生(新长(3),“20034140303“,“李四3“,“男”,22));   用于。add(新学生(新长(4),“20034140304“,“李四4“,“男”,23));   listMap.put (“class2",用于);   返回成功;   }   }

二。前端测试页面:testMap。jsp

Java代码

& lt; % @页面   contentType=皌ext/html; charset=UTF-8"   %比;=& lt; % @ taglib前缀“s"   uri=?struts-tags"%比;   & lt; html>   & lt; head>   & lt; title> struts2中地图的遍历总结& lt;/title>   & lt;/head>   & lt; body>   & lt; b> 1.中地图的关键为字符串,值为字符串字符串& lt;/b> & lt; br>   & lt;年代:迭代器值=https://www.yisu.com/zixun/"地图" id="列">   
  关键:
  价值:
     * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  <表边界=?”=?0%”单元格间距宽度=" 0 "单元格边距=" 0 ">      键=值    ID    num    名称   性   年龄      * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
   2.中映射的键为字符串,值为学生对象                                                   表>      <表边界=?”=?0%”单元格间距宽度=" 0 "单元格边距=" 0 ">      键=值    ID    num    名称   性   年龄      * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
   3.中映射的键为字符串,值为字符串数组                        

怎么在Struts2中利用OGNL表达式对地图进行遍历