==comments
1. Type 1: <!-- --> : HTML style, shown in the browser
2. Type 2: // or /* ... */ : Java style, not shown in the browser
3. Type 3: <%-- --%> : JSP styple, not shown in the browser
==Scriptlet
1. Type 1: <% %> : define variable and write java code
2. Type 2: <%! %>: define global variables
3. Type 3: <%= %>: output a variable content
<table border=1>
<%for(int i=0;i<10;i++) {%>
<tr>
<%for(int j=0;j<10;j++) {%>
<td><%=(i*j)%></td>
<%}%>
</tr>
<%}%>
</table>
==Dynamically print table
demo.html
<form method='post' action='demo.jsp'>
<table border=0>
<tr>
<td colspan=2>打印表格</td>
</tr>
<tr>
<td>行数</td>
<td><input type='text' name='rows'</td>
</tr>
<tr>
<td>列数</td>
<td><input type='text' name='cols'</td>
</tr>
<tr>
<td><input type='submit' value='打印'</td>
<td><input type='reset' value='重设'</td>
</tr>
</table>
</form>
demo.jsp
<%
int rows=Integer.parseInt(request.getParameter("rows"));
int cols=Integer.parseInt(request.getParameter("cols"));
%>
<table border=1>
<%for(int i=0;i<rows;i++) {%>
<tr>
<%for(int j=0;j<cols;j++) {%>
<td><%=(i*j)%></td>
<%}%>
</tr>
<%}%>
</table>
没有评论:
发表评论