example.jsp文件:
<%@ page language="java" import="java.util.*,com.neu.Student" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>Java程序片段和表达式练习</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
List<Student> stus = new ArrayList<Student>();
stus.add(new Student("张三","男",19));
stus.add(new Student("莉莉丝","女性",59));
stus.add(new Student("刘飞","男性",29));
%>
<table border="1" width="438" align="center">
<tr>
<th>姓名</th>
<th>性别</th>
<th>年龄</th>
</tr>
<%
for(Student s :stus){
%>
<tr>
<td align="center"><%=s.getName()%></td>
<td align="center"><%=s.getGender() %></td>
<td align="center"><%=s.getAge()%></td>
</tr>
<%
}
%>
</table>
</body>
</html>
Student.java文件:
package com.neu;
public class Student {
private String name;
private String gender;
private int age;
public Student() {
super();
}
public Student(String name, String gender, int age) {
super();
this.name = name;
this.gender = gender;
this.age = age;
}
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 int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}