jsp第二次作业 张垚

package com.example.zy;

public class Person {
    private int age;
    private String name;
    private int phone;
    private String sex;

    public Person() {
    }

    public Person(int age, String name, int phone, String sex) {
        this.age = age;
        this.name = name;
        this.phone = phone;
        this.sex = sex;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getPhone() {
        return phone;
    }

    public void setPhone(int phone) {
        this.phone = phone;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    @Override
    public String toString() {
        return "Person{" +
                "age=" + age +
                ", name='" + name + '\'' +
                ", phone=" + phone +
                ", sex='" + sex + '\'' +
                '}';
    }
}

<%@ 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 red solid;
            width: 600px;
            border-collapse: collapse;
        }
        td,th{
            border: 1px red solid;
        }
    </style>
</head>
<body>
 <%
     List<Person> list=new ArrayList<>();
     for (int i=0;i<2;i++){
         int t=18+i;
         list.add(new Person(r,"小明",11111+r,"男孩子"));
     }
 %>
 <table>
    <tr>
        <td>年龄</td>
        <td>名字</td>
        <td>性别</td>
        <td>手机号</td>
        <td>操作</td>
    </tr>
<%
    for (Person person : list) {%>

  <tr>
      <td><%=person.getAge()%></td>
      <td><%=person.getName()%></td>
      <td><%=person.getSex()%></td>
      <td><%=person.getPhone()%></td>
      <td>散步.打游戏</td>
  </tr>
 <%}%>
 </table>
</body>
</html>

 

 

  

  

posted @ 2021-03-14 18:15  zylx  阅读(32)  评论(0编辑  收藏  举报