集合操作

在Java Se中所有的集合都要使用Iterator方法进行输出,List接口对Collection接口进行了扩充,而Set没有进行扩充。对于每次需要保存一对儿内容的操作使用Map集合,而Map每次保存的都是Map.Entry接口对象,要想在web中很好的使用集合操作还是需要使用MVC进行操作。
print_Connection_demo.jsp
 
  1. <%  
  2. List all = new ArrayList() ;  
  3. all.add("张三") ;  
  4. all.add("www.MLDNJAVA.cn") ;  
  5. all.add("mldnqa@163.com") ;  
  6. request.setAttribute("allinfo",all) ; // 集合保存在request范围  
  7. %> 
  8. <h3>第一个元素:${allinfo[0]}</h3> 
  9. <h3>第二个元素:${allinfo[1]}</h3> 
  10. <h3>第三个元素:${allinfo[2]}</h3> 

以上的代码jsp关心的只有接受集合参数的那部分,其他部分使用Servet完成的。

print_Map_demo.jsp
 
  1. <%  
  2. Map map = new HashMap() ;  
  3. map.put("zs","张三") ;  
  4. map.put("mldn","www.MLDNJAVA.cn") ;  
  5. map.put("email","mldnqa@163.com") ;  
  6. request.setAttribute("info",map) ; // 集合保存在request范围  
  7. %> 
  8. <h3>KEY为lxh的内容:${info["zs"]}</h3> 
  9. <h3>KEY为mldn的内容:${info["mldn"]}</h3> 
  10. <h3>KEY为email的内容:${info["email"]}</h3>