jsp和java的结合使用显示学生信息
package com.zyz;
public class Student {
private String ID; // 学号
private String name; // 姓名
private String gender; // 性别
private String clas; // 班级
private double score; // 得分
public String getID() {
return ID;
}
public void setID(String iD) {
ID = iD;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getClas() {
return clas;
}
public void setClas(String clas) {
this.clas = clas;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
}
学生的基本信息封装起来。对外提供setxx()和getxx()方法进行操作。
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<%@ page import="com.zyz.Student"%>
<%@ page import="java.util.*"%>
<html>
<head>
<meta charset="UTF-8">
<title>所有学生信息</title>
</head>
<body>
<%
ArrayList<Student> list = new ArrayList<Student>();//储存信息
Student student1 = new Student();//学生的类
student1.setID("001");
student1.setName("李白");
student1.setGender("男");
student1.setClas("01");
student1.setScore(723.0);
list.add(student1);//加入集合
Student student2 = new Student();
student2.setID("002");
student2.setName("孟浩然");
student2.setGender("男");
student2.setClas("02");
student2.setScore(689.0);
list.add(student2);
Student student3 = new Student();
student3.setID("003");
student3.setName("杨玉环");
student3.setGender("女");
student3.setClas("03");
student3.setScore(600.0);
list.add(student3);
%>
<!-- HTML代码 -->
<table align="center" width="450"border 1>
<tr align="center">
<td colspan=5><h4>所有学生信息</h4></td>
</tr>
<tr align="center">
<td>学号</td>
<td>姓名</td>
<td>性别</td>
<td>班级</td>
<td>成绩</td>
</tr>
<!-- 循环转入数据 -->
<%
for (Student s : list) {
%>
<tr align="center">
<td><%=s.getID()%></td>
<td><%=s.getName()%></td>
<td><%=s.getGender()%></td>
<td><%=s.getClas()%></td>
<td><%=s.getScore()%></td>
</tr>
<%
}
%>
</table>
</body>
</html>
java和jsp的结合使用展示学生的基本信息