JSP第二次作业

利用Java程序片,用for二重循环输出一个3行5列的table

<%@ page import="com.example.zuoye.Person" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
<title>JSP - Hello World</title>
<style>
table{
border: 1px green solid;
width: 500px;
border-collapse: collapse;
}
td,th{
border: 1px green solid;
}
</style>
</head>
<body>
<%
List<Person> list=new ArrayList<>();
for (int i=0;i<2;i++){
int t=18+i;
list.add(new Person(t,"11",22+t,"33"));
}
%>
<table>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
</tr>
<%
for (Person person : list) {%>

<tr>
<td><%=person.getAge()%></td>
<td><%=person.getName()%></td>
<td><%=person.getSex()%></td>
<td><%=person.getPhone()%></td>
<td>55</td>
</tr>
<%}%>
</table>
</body>
</html>

 

posted on 2021-03-11 13:48  iM59  阅读(43)  评论(0编辑  收藏  举报

导航