jsp 的 for循环


jsp 的 for循环
jsp中同样可以使用for语句来循环输出内容。for与if一块使用会使得程序流程更加灵活。
达到一些我们想要的效果例如:
<%@ page language="java" contentType="text/html;" charset=utf-8"%>
<html>
<head><title>jsp Scriptlets</title>
<link rel='stylesheet' type='text/css' href='css/style.csss'>
</head>
<body>
<br/>
<%
   Object[] [] leters={
                 {true. "共享您注册的信息已经生效","e_360364641.qq.com","helloweenvsfei@
fmai.com","2012-8-8"},
                  {true,"Java EE 5.0 release!!","admin@sun.com","helloweenvsfei@gmail.com",
"2007-6-24"},
                  {false,"l来信已经收到,下周开始工作","foo@bar.com","helloweenvsfei@gmail
 .com","2007-5-25"},
                   {fale,"您的信箱有留言","360364641@qq.com","helloweenvsfei@gmail.com"
,"2007-3-25"},
};
String[] colors={"#DDDDDD","#AAAAAA",};
%>
     <table horder=0 cellspacing=1 cellpadding=2 width=700 align=center>
         <tr style="background: url(images/vertical_line.gif);">
               <td align="ceter" style="line-height:22px;">&nbsp;</td>
               <td align="ceter"style="ine-height:22px">标题&nbsp;</td>
               <td align="ceter"style="line-height:22px;">发件人&nbsp</td>
               <td align="ceter"style="line-height:22px;">收件人&nbsp</td>
  <td align="ceter"style="line-height:22px;">时间&nbsp</td>
      </tr>
<%
for(int i=0;i<letters.length;ii++){
Object[] letter=letters[i];
%>
          <tr style='background:<%=colors[i%2]%>'>
               <td   align="center">
                   <%
                         if(lttter[0]==Boolean.TRUE){
                  %>
                          <img src="images/mail.gif"/>
                       <%
                            }
                                       else{
                                                  out.println("&nbsp;");
                          }
                         %>
                      </td>
                      <td><a href="#"><%=letter[1]%></a></td>
                      <td><%=letter[2]%></td>
                     <td><%=letter[3]%></td>
                      <td aling="cenetr"><%=letter[4]%></td>
                    </tr>
<%
}
%>
    </table>
</body>
</html>
在该程序中for循环内部使用if语句判断是否为新邮件,如果是新邮件,则邮件状态列显示邮件图标,否则
显示一个空格字符

 


免责声明!

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



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