Map<String, List<OfferBean>> map = new HashMap<String, List<OfferBean>>();
List<OfferBean> al=new ArrayList<OfferBean>();
List<OfferBean> bl=new ArrayList<OfferBean>();
OfferBean of=null;
sql="select * from catgory";// here i'm using one table data
ps1=c.prepareStatement(sql);
ps1.execute();
rs=ps1.getResultSet();
while(rs.next())
{
of=new OfferBean();
of.setCategory(rs.getString("catgoryname"));
al.add(of);
}
sql="select * from projectname where sl_no_projectname";//here on more table data
ps1=c.prepareStatement(sql);
ps1.execute();
rs=ps1.getResultSet();
while(rs.next())
{
of=new OfferBean();
of.setCategory(rs.getString("categoryname"));
bl.add(of);
}
map.put("key", al); // here i'm put two table data in the map using keys
map.put("key1",bl);
return map;
当我使用jstl在jsp端进行检索时,如何分隔两个键,如下所示:
<c:forEach var="sample" items="${sampleMap}">
Key : ${sample.key}
<c:forEach var="item" items="${sample.value}">
<option>${item.category}</option>
</c:forEach>
</c:forEach>
我想将两个表数据放在两个不同的地方。
最佳答案
更好的选择是将map替换为两个单独的列表。
在服务器端
request.setAttribute("al", al);
request.setAttribute("bl", bl);
or
request.setAttribute("al",map.get("key"));
request.setAttribute("bl",map.get("key1"));
在jsp中
<c:forEach var="a" items="${al}">
<option>${a.category}</option>
</c:forEach>
<c:forEach var="b" items="${bl}">
<option>${b.category}</option>
</c:forEach>