通过JSTL+EL实现循环迭代
2015-07-08 12:39
771 查看
使用前需要导入包 jstl.jar 和 standard.jar
<%@ page language="java" import="java.util.*,com.wzh.test.*" pageEncoding="UTF-8"%> <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>使用el+jstl完成数据迭代</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body><br> <% List list=new ArrayList(); list.add(new Person("aa")); list.add(new Person("bb")); list.add(new Person("cc")); request.setAttribute("slist", list); %> <c:forEach items="${slist }" var="person"> ${person.name} </br> </c:forEach> <% Map map = new HashMap(); map.put("aa", new Person("aaa")); map.put("bb11", new Person("bbb")); request.setAttribute("smap", map); %> <c:forEach items="${smap }" var="entry"> ${entry.key } : ${entry.value.name } </br> </c:forEach> <c:if test="${user!=null }"> 欢迎您:${user.username } </c:if> <c:if test="${user==null }"> 请登录 </c:if> </body> </html>
相关文章推荐
- 精通JavaScript开发课时11(DOM基础)笔记
- javascript笔记04:let语句 和 yield语句 和 with语句
- js中如何实现数字相加
- json-lib 之jsonConfig详细使用
- js 页面智能判断浏览器版本
- 详细分析JavaScript变量类型
- 【探秘ES6】系列专栏
- js实现图片点击左右轮播
- CommonJS,AMD,CMD规范
- javascript获取重复次数最多的字符
- ajax跨域和anglarjs跨域
- javascript构造函数类和原型prototype定义的属性和方法的区别
- JS的预编译和执行顺序 详析
- Package.json小结
- javascript连续赋值问题
- 精通JavaScript开发课时12(DOM操作应用)笔记
- Javascript秘密花园[摘录]
- js之事件冒泡和事件捕获详细介绍
- 服务器采用JSON格式返回数据给安卓客户端
- javascript真的是异步的吗?且看setTimeout的实现原理以及setTimeout(0)的使用场景