- 举例:使用jsp在页面打印99乘法表
<%
for (int i = 1; i <= 9; i++) {
for (int j = 1; j <= i; j++) {
out.write(j + "*" + i + "=" + (i * j) + " ");
}
out.write("<br>");
}
%>
- 输出一个java的对象
<%
Student wzy = new Student("王子玉",18,(byte)0, "123456789");
out.write(wzy.toString());
%>
- 使用table遍历对象
<%
StudentService studentService = new StudentService();
List<Student> students = studentService.getAll();
%>
<table border="1">
<tr>
<th>序号</th>
<th>姓名</th>
<th>性别</th>
<th>年龄</th>
<th>手机号</th>
</tr>
<%
for (int i = 0; i < students.size(); i++) {
%>
<tr>
<td><%=i+1 %></td>
<td><%=students.get(i).getName() %></td>
<td><%=students.get(i).getSex() == 1 ? "男" : "女" %></td>
<td><%=students.get(i).getAge() %></td>
<td><%=students.get(i).getMobile() %></td>
</tr>
<%
}
%>
</table>