博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
jsp 导入自己写的类并使用输出
阅读量:4190 次
发布时间:2019-05-26

本文共 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 List
getAll(){ 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 <% List
list = 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/

你可能感兴趣的文章
java中xml的解析
查看>>
http watch工具的使用
查看>>
验证码VerifyCode
查看>>
登录+验证码
查看>>
Eclipse中启动tomcat访问404解决及原因
查看>>
jsp详解
查看>>
jsp 导入自己写的类并使用输出
查看>>
jsp 注释
查看>>
jsp 指令
查看>>
jsp 9大内置对象
查看>>
MySQL 5.7.27 详细下载安装配置教程
查看>>
使用Git制作和提交patch
查看>>
从0开始运行主线Linux内核
查看>>
leetcode 505 迷宫2
查看>>
小孩编程积木玩具
查看>>
科学育儿书籍
查看>>
emacs 学习
查看>>
cygwin
查看>>
内核页表
查看>>
github
查看>>