jsp el表达式,for循环

  1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>  
  2. <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>  
  3. <%  
  4.     List list = new ArrayList();  
  5.     for (int i = 0; i < 10; i++) {  
  6.         list.add(i);  
  7.     }  
  8.     session.setAttribute("list", list);  
  9. %>  
  10.   
  11. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">  
  12. <html>  
  13.   <head>  
  14.       
  15.     <title>My JSP 'index.jsp' starting page</title>  
  16.     <meta http-equiv="pragma" content="no-cache">  
  17.     <meta http-equiv="cache-control" content="no-cache">  
  18.     <meta http-equiv="expires" content="0">      
  19.     <style type="text/css">  
  20.     tr.foreach_tr1{background-color:#D7E9FD;color:black;}  
  21.     tr.foreach_tr2{background-color:#A7DBFF; color:black ;}  
  22.     </style>  
  23.   </head>  
  24.     
  25.   <body>  
  26.     <table border="1" width="200" cellpadding="0" cellspacing="0">  
  27.         <tr align="center"  class="first_tr">  
  28.             <td>  
  29.                 test  
  30.             </td>  
  31.         </tr>  
  32.         <c:forEach items="${list}" varStatus="i" var="item" >  
  33.             <c:if test="${i.index % 2 == 0}" >  
  34.                 <tr align="center" class="foreach_tr1">  
  35.             </c:if>  
  36.             <c:if test="${i.index % 2 == 1}">  
  37.                 <tr align="center" class="foreach_tr2">  
  38.             </c:if>  
  39.             <td>  
  40.                 <h2>${item}</h2>  
  41.             </td>  
  42.         </tr>  
  43.         </c:forEach>  
  44.     </table>  
  45.   </body>  
  46. </html>  

刚刚忘记在文件头上加:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>  
结果显示就没有循环出来了...

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值