jsp遍历、循环


<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

1.

<%
   Test test  = new Test();
   List listTest = test.getlist();//得到List对象()
   request.setAttribute("testList", listTest );//把List设置到Request对象中
%>
<c:forEach items="${testList}" var="list" varStatus="s"> 

2.

<c:forEach var="i" begin="1" end="10" step="1">
    ${i}
</c:forEach>

3.

<%
    Date d=new Date();
    d.getTime();
    SimpleDateFormat sdf=new SimpleDateFormat("yyyy");
    String year=sdf.format(d);
    List<String> yearList=new ArrayList<String>();
    for(int i=0;i<8;i++){
    int y=Integer.parseInt(year);
    yearList.add(y-i+"");
    }
%>
<c:forEach  var="y" items="<%=yearList %>"> 
    <li>${y}</li>
</c:forEach>

  

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM