集合操作
- <%
- List all = new ArrayList() ;
- all.add("张三") ;
- all.add("www.MLDNJAVA.cn") ;
- all.add("mldnqa@163.com") ;
- request.setAttribute("allinfo",all) ; // 集合保存在request范围
- %>
- <h3>第一个元素:${allinfo[0]}</h3>
- <h3>第二个元素:${allinfo[1]}</h3>
- <h3>第三个元素:${allinfo[2]}</h3>
以上的代码jsp关心的只有接受集合参数的那部分,其他部分使用Servet完成的。
- <%
- Map map = new HashMap() ;
- map.put("zs","张三") ;
- map.put("mldn","www.MLDNJAVA.cn") ;
- map.put("email","mldnqa@163.com") ;
- request.setAttribute("info",map) ; // 集合保存在request范围
- %>
- <h3>KEY为lxh的内容:${info["zs"]}</h3>
- <h3>KEY为mldn的内容:${info["mldn"]}</h3>
- <h3>KEY为email的内容:${info["email"]}</h3>