Java Web學習筆記--JSP for循環


JSP for循環

<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<html>
<head><title>JSP Scriptlets</title>
<link rel='stylesheet' type='text/css' href='css/style.css'>
</head>
<body>
<br/>
<%
    Object[][] letters = {
        {true, "恭喜您的信息已生效", "e_inn@163.com", "helloxr@gmail.com", "2007-8-8"},
        {true, "Java EE 7.0 release!!", "admin@oracle.com", "helloxr@gmail.com", "2007-6-24"},
        {false, "來信已經收到,下周末見面商談", "foo@bar.com", "helloxr@gmail.com", "2007-5-20"},
        {false, "您的博客有新的留言", "blog@foo.bar.com", "helloxr@gmail.com", "2007-3-2"}
    };
    String[] colors = {"#DDDDDD", "#AAAAAA"};
%>
    <table border="0" cellspacing="1" cellpadding="2" width="700" align="center">
        <tr style="background: url(images/vertical_line.gif);">
            <td align="center" style="line-height: 22px; ">&nbsp;</td>
            <td align="center" style="line-height: 22px; ">標題&nbsp;</td>
            <td align="center" style="line-height: 22px; ">發信人&nbsp;</td>
            <td align="center" style="line-height: 22px; ">收信人&nbsp;</td>
            <td align="center" style="line-height: 22px; ">時間&nbsp;</td>
        </tr>
<%
    for(int i = 0; i < letters.length; i++){
    Object[] letter = letters[i];

%>
    <tr style="background: <%= colors[i%2] %>">
        <td align="center">
            <%
                if(letter[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 align="center"><%= letter[4] %></td>
    </tr>
<%
    }
%>
    </table>
</body>
</html>

 

瀏覽效果:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM