package Day01;
import java.util.Date;
import java.util.List;
public class week1{
private String id; //学号
private String name; //姓名
private String sex; //性别
private int age; //年龄
private String phone;
private String birth; //生日
private List<String> favorites;//爱好
//ArrayList类方法
public week1(String id,String name,String sex,int age,String phone,String birth,List<String>favorites) {
super();
this.id=id;
this.name=name;
this.sex=sex;
this.age=age;
this.phone=phone;
this.birth=birth;
this.favorites=favorites;
//有参
}
//无参
// public week3() {
// super();
// }
public String getId() {
return id;
}
public void setId(String id) {
this.id =id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getBirth() {
return birth;
}
public void setBirth(String birth) {
this.birth = birth;
}
public List<String> getFavorites() {
return favorites;
}
public void setFavorites(List<String> favorites) {
this.favorites = favorites;
}
public String toString() {
return "学号:"+ id +"\n"+"姓名:"+name+"\n"+"性别:"+sex+"\n"+"年龄"+age+"\n"+"电话"+phone+"\n"+"生日"+birth+"\n"+"爱好"+favorites;
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@page import ="Day01.week1"%>
<%@page import ="java.util.*"%>
<%@ taglib prefix = "c" uri ="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix ="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
List<week1> list = new ArrayList<week1>();
List<String> favorites1 =new ArrayList<String>();
favorites1.add("唱歌");
favorites1.add("跳舞");
week1 zhang=new week1("001","张三","1",18,"12300000000","1999-03-01",favorites1);
list.add(zhang);
List<String> favorites2 =new ArrayList<String>();
favorites2.add("下棋");
favorites2.add("打球");
week1 li=new week1("002","李四","1",19,"13800000000","2000-03-01",favorites2);
list.add(li);
List<String> favorites3 =new ArrayList<String>();
favorites3.add("学习");
favorites3.add("唱歌");
week1 wang=new week1("003","小王","0",20,"15800000000","2001-03-01",favorites3);
list.add(wang);
request.setAttribute("stus",list);
%>
<table border="1" cellpadding="0" cellSpacing="0" align="center" width="80%">
<tr>
<td>学号</td>
<td>姓名</td>
<td>性别</td>
<td>年龄</td>
<td>电话</td>
<td>生日</td>
<td>爱好</td>
</tr>
<c:forEach var="stu" items="${requestScope.stus}">
<tr>
<td>${stu.id}</td>
<td>${stu.name}</td>
<td>
<c:if test="${stu.sex==1 }">
男
</c:if>
<c:if test="${stu.sex==0 }">
女
</c:if>
</td>
<td>${stu.age}</td>
<td>${stu.phone}</td>
<td>${stu.birth}</td>
<td>
<c:forEach var="f" items="${stu.favorites }">
${f }
</c:forEach>
</td>
</tr>
</c:forEach>
</table>
</body>
</html>
|