Student.java
package text.bean;
public class Student {
private String name;
private int age;
private int height;
public Student() {
super();
}
public Student(String name, int age, int height) {
super();
this.name = name;
this.age = age;
this.height = height;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
}
jstl.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="java.util.*,com.ujiuye.bean.*"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
Student stu1 = new Student("张三",20,175);
Student stu2 = new Student("李四",30,160);
Student stu3 = new Student("王五",40,170);
Student stu4 = new Student("姚明",40,225);
Student stu5 = new Student("长江",60,155);
Student stu6 = new Student("赵六",10,175);
List<Student> list = new ArrayList();
list.add(stu1);
list.add(stu2);
list.add(stu3);
list.add(stu4);
list.add(stu5);
list.add(stu6);
//放入到作用域中
request.setAttribute("list", list);
%>
<table border="1">
<tr>
<th>姓名</th>
<th>年龄</th>
<th>身高</th>
</tr>
<c:forEach items="${list}" var="stu" varStatus="xx">
<tr>
<td>${stu.name}</td>
<td>${stu.age}</td>
<td>${stu.height}</td>
</tr>
</c:forEach>
</table>
</body>
</html>


本文介绍了一个使用Java编写的Student类,该类包含了学生的基本信息如姓名、年龄和身高,并通过JSP页面结合JSTL标签库展示了一组学生数据。在JSP页面中,创建了多个Student对象并将其存储在List集合中,最后利用JSTL的forEach标签循环遍历并显示这些学生的信息。
2773

被折叠的 条评论
为什么被折叠?



