请教各位:List<map>型的数据怎么在jsp页面展示出来?用什么标签都可以。 现在有一个list集合,里面存放的是map(list里面大概放了50个map元素),map里面的内容是<1,"xx">的形式(每个map里面放了大概100条这样的数据),请教各位怎么把这个list里面的元素在jsp页面展示出来?最好能用struts2.0的标签实现,用其他标签也行,谢谢各位了。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 <logic:present name= "list "> <logic:iterate name= "list " id= "map" scope= "request "> <bean:write name= "map " property= "mapkey"/> </ogic:iterate></logic:present>可能是这样写,没试过哦。 这个俺 常用。<table><s:iterator value="list"><tr> <td><s:property value="1"></td> <td><s:property value="2"></td> <td><s:property value="3"></td></tr></s:iterator></table>这是大概意思,我机器调不了,list 是你的上下文中存的List对象的名字,1,2,3是你map 的key <s:iterator value="list" var="list"></s:iterator> 使用Struts2的标签的话,可以简化一点难度,下面的方案只是一个大致的思路,需要LZ自己进一步去调试:假设LZ所说的list保存在request范围内,名称为reqList。界面代码如下:<s:iterator value="#request.reqList" id="lstMap"> <s:iterator value="lstMap" id="mapElement"> <s:property value='key'/> <s:property vlaue='value'/> </s:iterator></s:iterator> 出现诸如 List<Map<K, V>>、Map<K, Map<K, V>> 等等此类结构的代码的话,这样的代码写得并不好,建议重新设计。 谢谢楼上几位,我在两个框架下,一个是struts1.0,另一个是struts2.0,分别按你们说的方法试过了,还是不行。要求是这样的:给一张表,表中有50个字段,注意是50个字段,并且这张表没有id,里面大概有100条数据,要求把数据取出来展示到jsp页面上,jsp页面要求自己写。数据取出来不难,难的是怎么在页面展示出来,我实在是想不到更好的设计方式了才把数据放到map里用list的,你看了之后能给出比较好的设计吗?谢谢了 struts的标签 <nested-el:iterate property="list"> <li><a href=""><nested-el:write property="字段名"/></a></li> </nested-el:iterate>或者JSTL的标签 <c:forEach items="${list}" var="list"> <li>${list.字段名}</li> </c:forEach> <logic:iterator id="bean" name="list" scope="request">${bean.属性}</<logic:iterator > 这么麻烦,直接这样这跟ID有什么关系? 请楼主将 struts标签 从头到尾在看一遍,只需要10分钟吧!!!!! 我在eclipse里面测试过了,原先的代码需要小修改一下,修改后如下:<s:iterator value="reqList" id="lstMap"> <s:iterator value="lstMap" id="mapElement"> <s:property value='key'/> <s:property value='value'/> </s:iterator></s:iterator>以上红色部分是修改的内容,已测试证明代码是可行的,请LZ再试试。 CSDN的论坛显示有些问题,只能将代码再贴一下了:以下是界面的代码:<s:iterator value="reqList" id="lstMap"> <s:iterator value="lstMap" id="mapElement"> <s:property value='key'/> <s:property value='value'/> </s:iterator></s:iterator>以下是action的部分代码,用来生成list和map,注意其属性reqList的名称与上面代码的对应:public class HelloWorld extends ExampleSupport { public List<Map> reqList = new ArrayList<Map>(); public List<Map> getReqList() { return reqList; } public void setReqList(List<Map> reqList) { this.reqList = reqList; } public String execute() throws Exception { setMessage(getText(MESSAGE)); Map[] myMap = new HashMap[50]; for (int i=0; i<50; i++) { myMap[i] = new HashMap<Integer,String>(); for(int j=0; j<100; j++) { myMap[i].put(j, i+"map"+j); } reqList.add(myMap[i]); } return SUCCESS; }…… Tomcat假死问题! 急! 《经济学人》上的一个动态效果,用什么技术实现的??有图,有链接 java.lang.OutOfMemoryError: Java heap space 问题 请相关人士看一下这个网站值多少钱? 帮忙看下什么问题,怎么解决?急!!! 如何获取数据库下最近的一条记录 jsp在linux环境下,上传下载程序出现中文就不能正常下载 (Java)客户端调用系统计算器 最近新学JSP 到了javabean时 除了问题 帮看一下 谢谢 用户和密码的验证问题! 在发布项目的时候报这个错误?100分求助!!!!!!!!!!!!!!!! 动态生成树型菜单方法有多少种
<logic:iterate name= "list " id= "map" scope= "request ">
<bean:write name= "map " property= "mapkey"/>
</ogic:iterate>
</logic:present>
可能是这样写,没试过哦。
<table>
<s:iterator value="list">
<tr>
<td><s:property value="1"></td>
<td><s:property value="2"></td>
<td><s:property value="3"></td>
</tr>
</s:iterator>
</table>这是大概意思,我机器调不了,
list 是你的上下文中存的List对象的名字,1,2,3是你map 的key
</s:iterator>
<s:iterator value="#request.reqList" id="lstMap">
<s:iterator value="lstMap" id="mapElement">
<s:property value='key'/>
<s:property vlaue='value'/>
</s:iterator>
</s:iterator>
要求是这样的:给一张表,表中有50个字段,注意是50个字段,并且这张表没有id,里面大概有100条数据,要求把数据取出来展示到jsp页面上,jsp页面要求自己写。数据取出来不难,难的是怎么在页面展示出来,我实在是想不到更好的设计方式了才把数据放到map里用list的,你看了之后能给出比较好的设计吗?谢谢了
<li><a href=""><nested-el:write property="字段名"/></a></li>
</nested-el:iterate>
或者JSTL的标签 <c:forEach items="${list}" var="list">
<li>${list.字段名}</li>
</c:forEach>
<logic:iterator id="bean" name="list" scope="request">
${bean.属性}
</<logic:iterator >
这么麻烦,直接这样
这跟ID有什么关系?
我在eclipse里面测试过了,原先的代码需要小修改一下,修改后如下:<s:iterator value="reqList" id="lstMap">
<s:iterator value="lstMap" id="mapElement">
<s:property value='key'/>
<s:property value='value'/>
</s:iterator>
</s:iterator>以上红色部分是修改的内容,已测试证明代码是可行的,请LZ再试试。
CSDN的论坛显示有些问题,只能将代码再贴一下了:以下是界面的代码:<s:iterator value="reqList" id="lstMap">
<s:iterator value="lstMap" id="mapElement">
<s:property value='key'/>
<s:property value='value'/>
</s:iterator>
</s:iterator>以下是action的部分代码,用来生成list和map,注意其属性reqList的名称与上面代码的对应:public class HelloWorld extends ExampleSupport {
public List<Map> reqList = new ArrayList<Map>(); public List<Map> getReqList() {
return reqList;
} public void setReqList(List<Map> reqList) {
this.reqList = reqList;
} public String execute() throws Exception {
setMessage(getText(MESSAGE));
Map[] myMap = new HashMap[50];
for (int i=0; i<50; i++) {
myMap[i] = new HashMap<Integer,String>();
for(int j=0; j<100; j++) {
myMap[i].put(j, i+"map"+j);
}
reqList.add(myMap[i]);
}
return SUCCESS;
}
……