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