out.println与<%!%>的功能一样

时间:2023-02-06 21:22:17
<%!
public static final String DBDRIVER = "A";
public static final String DBURL = "b";
public static int add(int i,int j){
return i+j;
}
%>
<br>
<h1><%=add(10,20) %></h1>
<br>
<%
int sum = 0;
for(int i = 0; i <=100; i++)
{
sum +=i;
}
out.print("<h1>sum=" +sum+DBDRIVER+DBURL+add(10,20)+"</H1>");
%>
<br>
<%
out.println("<table border = \"1\">");
for(int i = 0; i<100; i++){
out.println("<tr>");
for(int j = 0 ; j<100; j++){
out.print("<td>"+i+"x"+j+"</td>");
}
out.println("</tr>"); }
out.println("</table>");
%> <br> <table border = "1">
<%
for (int i = 0; i<100;i++){
%>
<tr>
<%
for (int j=0; j<100; j++)
{
%>
<td><%=i %>x<%=j %></td>
<%
}
%>
</tr>
<%
}
%>
</table>

使用<%=%> 比out.print()要好。