本文共 1566 字,大约阅读时间需要 5 分钟。
1、创建student.java类
package test;import java.util.ArrayList;import java.util.List;public class student { private String name; private int age; private String sex; 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 String getSex() { return sex; } public void setSex(String sex) { this.sex = sex; } public student() { super(); // TODO Auto-generated constructor stub } public student(String name, int age, String sex) { super(); this.name = name; this.age = age; this.sex = sex; } @Override public String toString() { return "students [name=" + name + ", age=" + age + ", sex=" + sex + "]"; } public static ListgetAll(){ List list = new ArrayList (); list.add(new student("zhansan", 20, "male")); list.add(new student("lili", 21, "female")); list.add(new student("wangwu", 19, "male")); return list; }}
2、创建index.jsp
<%@ page language="java" import="java.util.*,test.student" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>hello jsp <% Listlist = student.getAll(); %>
<% for(student stu : list){%> 姓名 年龄 性别 <% }%> <%=stu.getName() %> <%=stu.getAge() %> <%=stu.getSex() %>
3、在 index.jsp的 <%@ page language="java" import="java.util.*,test.student" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>这句中导入了路径为test.student的类4、查看结果
转载地址:http://owloi.baihongyu.com/