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;"> </td>
<td align="ceter"style="ine-height:22px">標題 </td>
<td align="ceter"style="line-height:22px;">發件人 </td>
<td align="ceter"style="line-height:22px;">收件人 </td>
<td align="ceter"style="line-height:22px;">時間 </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(" ");
}
%>
</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語句判斷是否為新郵件,如果是新郵件,則郵件狀態列顯示郵件圖標,否則
顯示一個空格字符