DAO类实现查找数据并放入一个map
public Map<String,Integer> getAllBlock_multi(String projectname)
{
LinkedHashMap <String,Integer> map=new LinkedHashMap<String,Integer>();
List<String> listTotal=new ArrayList<String>(); Connection conn=null; Statement stmt=null; ResultSet rs=null;
projectname=projectname.replace(",","|");
try{
conn=Conn.getConnection();
stmt=conn.createStatement();
String sql="select Component, sum(Total) as Total, sum(COUNT) as COUNT from block_total where ProjectName REGEXP '"+projectname+"'group by Component order by Total desc,Component
";
rs=stmt.executeQuery(sql);
while(rs.next())
{
map.put(rs.getString("Component"), rs.getInt("COUNT"));
}
}
catch(Exception ex)
{
ex.printStackTrace();
}
finally
{
try
{
if(rs!=null)
{
rs.close();
rs=null;
}
if(stmt!=null)
{
stmt.close();
stmt=null;
}
if(conn!=null)
{
conn.close();
conn=null;
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
return map;
}
Acti
Map<String,Integer> map2= dad.getAllBlock_multi(pn);
List<String> listBlock1=new ArrayList<String>(); List<String> listBlock2=new ArrayList<String>(); Set<String> keysBlock=map2.keySet(); Iterator<String> iterBlock1=keysBlock.iterator(); while(iterBlock1.hasNext()){ listBlock1.add(iterBlock1.next()); } Collection<Integer> valuesBlock=map2.values(); Iterator<Integer> iterBlock2=valuesBlock.iterator(); while(iterBlock2.hasNext()){ listBlock2.add(iterBlock2.next()+""); } request.put("BlockItem1", listBlock1.get(0).replace("Closed", "")); request.put("BlockItem2", listBlock1.get(4).replace("Closed", "")); //....................
request.put("BlockClose1", listBlock2.get(0));
动态刷新页面 从第N页跳转到别的页面, 返回的时候, 还回到原来页面的方法:
1. index.jsp页面设置超链接时添加当前页面码数:
html = html+ "<tr><td>" +person[i].getElementsByTagName("pid")[0].firstChild.data+"</td><td><a href=login_success.jsp?cur="+currpage+">" +person[i].getElementsByTagName("pname")[0].firstChild.data+"</a></td><td>" +person[i].getElementsByTagName("age")[0].firstChild.data +"</td></tr>";
2. 跳转页面获取参数并设置超链接时把参数再传回去:
<a href="index.jsp?c=<%=request.getParameter("cur")%>">登陆成功</a>
3. 首页获取后, 变量取得作为显示页面的函数参数:
<script> var t; t=(<%=request.getParameter("c")%>==null)?1:<%=request.getParameter("c")%>; </script> <body onLoad=AjaxTest(t)>