JSP頁面打印輸出,兩種方法。out、《%=


使用out.println()輸出:

<%@ page contentType="text/html;charset=UTF-8"%>  
<html>  
<head><title>乘法口訣</title></head>  
<body>  
    使用out.println()打印乘法口訣:<br/>  
    <%  
        int cols,rows;  //列、行  
        out.println("<table border='1'>");          
        for(cols=1;cols<10;cols++){  
            out.println("<tr>");  
            for(rows=1;rows<=cols;rows++){  
                out.println("<td>"+cols+"*"+rows+"="+cols*rows+"</td>");  
            }  
            out.println("</tr>");       
        }         

        out.println("</table>");  
    %>  
</body>  
</html>

使用<%= %>表達式輸出:

<%@ page contentType="text/html;charset=UTF-8"%>  
<html>  
<head><title>乘法口訣</title></head>  
<body>  
    使用<%=%>表達式打印乘法口訣:<br/>  
    <table border='1'>  
    <%  
        int cols,rows;  //列、行  
        for(cols=1;cols<10;cols++){  
    %>  
        <tr>  
    <%  
            for(rows=1;rows<=cols;rows++){  
    %>  
                <td><%=cols%>*<%=rows%>=<%=cols*rows%></td>  
    <%  
            }  
    %>                 
        </tr>   
    <%  
        }         
    %>  
    </table>  
</body>  
</html> 

 


免責聲明!

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



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