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>