Jsp 标签之<c:foreach>循环
2016-10-19 00:44
726 查看
jsp要使用foreach
一:前提
1:在maven中引入jstl包,并且在jsp上要引入
<%@ tagliburi=”http://java.sun.com/jsp/jstl/core”prefix=”c”%>
<%@ tagliburi=”http://java.sun.com/jstl/fmt”prefix=”fmt”%>
2:因为jsp本身不支持el表达式,所以需要声明
<%@ page isELIgnored=”false”%>
二:使用目的
我们的页面可能需要循环生成模板,这时候可以使用foreach来达到目的
以jfinal为例子
比如说我们通过查询得到两个list集合,list1,list2
我们要在list1循环内再循环list2才能得到我们需要的页面效果
parentColumn为主导航栏
sonColumn为主导航栏下的副导航栏,
2个column类包含id,parent_id.
parentColumn的parent_id=0
sonColumn的parent_id=parentColumn.id
我们在页面上
这样就可以在页面上生成模板。
一:前提
1:在maven中引入jstl包,并且在jsp上要引入
<%@ tagliburi=”http://java.sun.com/jsp/jstl/core”prefix=”c”%>
<%@ tagliburi=”http://java.sun.com/jstl/fmt”prefix=”fmt”%>
2:因为jsp本身不支持el表达式,所以需要声明
<%@ page isELIgnored=”false”%>
二:使用目的
我们的页面可能需要循环生成模板,这时候可以使用foreach来达到目的
以jfinal为例子
比如说我们通过查询得到两个list集合,list1,list2
我们要在list1循环内再循环list2才能得到我们需要的页面效果
parentColumn为主导航栏
sonColumn为主导航栏下的副导航栏,
2个column类包含id,parent_id.
parentColumn的parent_id=0
sonColumn的parent_id=parentColumn.id
//后台代码 list<parentColum> list1=new ArrayList<parentColum>(); List<sonColum> list2=new ArrayList<sonColum>(); setAttr("parentColums",list1); setAttr("sonColums",list2); render("demo.jsp");
我们在页面上
<c:foreach items="${parentColumns}" var="${column}"> <div> <a>${colum.name}</a> <c:foreach items="${sonColumns}" var="${sonColumn}"> <c:if test="${colum.id==sonColumn.parent_id}"> <li>${soncolum.name}</li> </c:if> </c:foreach> </div> </c:foreach>
这样就可以在页面上生成模板。
相关文章推荐
- JSP中使用<c:forEach>标签循环遍历元素
- 【JSP EL】<c:if> <c:foreach >EL表达式 获取list长度/不用循环,EL在List中直接获取第一项的内容/EL获取Map的键,Map的值
- Jsp标签之<c:forEach>
- JSP的<c:choose><c:forEach><c:if><c:when><c:set>标签
- JSP<c:forEach >标签属性
- jsp页面中jstl标签详解 包括< c:choose><c:foreach> <c:when> <c:otherwise>
- Jsp中如何在<c:forEach >标签内获取items集合的长度方法
- jsp <c:forEach> 标签属性解析
- Strust2 <c:forEach> 循环控制标签
- <c:foreach> 标签怎么获取循环次数?
- jsp页面动态展示list-使用<select>和<c:forEach>标签
- JSP的<c:choose> <c:forEach> <c:if> <c:when> <c:set>标签
- jsp <c:forEach>循环 以及怎么统计变量的总数量
- JSP的<c:choose><c:forEach><c:if><c:when><c:set>标签
- Jsp中<c:foreach>如何循环得到值,进行修改
- 【JSP JSTL】<c:if>多个判断条件 + <c:foreach>满足条件跳出循环
- jsp标签<c:forEach>取出传递参数注意
- JSTL <c:forEach> 标签终止循环
- jstl标签<c:forEach>如何获取循环子级元素值
- Jsp中如何在<c:forEach >标签内获取items集合的长度方法