JSP之EL表达式之遍历

来源:互联网 发布:游族网络 大皇帝 手游 编辑:程序博客网 时间:2024/05/17 07:32

使用EL表达式获取(Student)对象,(List)集合,(Map)集合的内容

获取对象

<%  /先创建对象  Student student = new Student("evan_qb",20);  //存入域对象中  pageContext.setAttribute("student", student);%><!-- 从域对象中取数据 -->姓名:${student.name}   年龄 ${student.age} 
获取List集合的内容

<%List<Student>  list = new ArrayList<Student>();list.add(new Student("张三",20));list.add(new Student("李四",21));list.add(new Student("王五",22));//放入域中pageContext.setAttribute("list",list); %>姓名:${list[0].name},年龄:${list[0].age }姓名:${list[1].name},年龄:${list[1].age }姓名:${list[2].name},年龄:${list[2].age }
遍历Map集合

<%  Map<String,Student> map = new HashMap<String,Student>();map.put("100",new Student("张三",20));map.put("101",new Student("李四",21));map.put("102",new Student("王五",23));//放入域中pageContext.setAttribute("map",map);%> <%--使用EL获取Map对象 --%>姓名:${map['100'].name },年龄:${map['100'].age }<br/>姓名:${map['101'].name },年龄:${map['101'].age }<br/>姓名:${map['102'].name },年龄:${map['102'].age }<br/>