第二周jsp

package com.example.zuoye;

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 + '\'' +
                '}';
    }
}

jsp

<%@ 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(t,"孙何伟",188845+t,"女孩子"));
     }
 %>
 <table>
    <tr>
        <td>age</td>
        <td>name</td>
        <td>sex</td>
        <td>number</td>
        <td>object</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-10 10:47  啪啪怪  阅读(58)  评论(0编辑  收藏  举报