javaBean 练习—封装学生信息

编写一个封装学生信息的JavaBean对象,在页面中调用该对象,并将学生信息输出在页面中。

 1 package com.sp.test;
 2 
 3 public class Student {
 4     private String name;
 5     private int xuehao;
 6     private String sex;
 7     private String banji;
 8     public String getName() {
 9         return name;
10     }
11     public void setName(String name) {
12         this.name = name;
13     }
14     public int getXuehao() {
15         return xuehao;
16     }
17     public void setXuehao(int xuehao) {
18         this.xuehao = xuehao;
19     }
20     public String getSex() {
21         return sex;
22     }
23     public void setSex(String sex) {
24         this.sex = sex;
25     }
26     public String getBanji() {
27         return banji;
28     }
29     public void setBanji(String banji) {
30         this.banji = banji;
31     }
32     public Student(String name, int xuehao, String sex, String banji) {
33         super();
34         this.name = name;
35         this.xuehao = xuehao;
36         this.sex = sex;
37         this.banji = banji;
38     }
39     @Override
40     public String toString() {
41         return "Student [姓名=" + name + ", 学号=" + xuehao + ", 性别=" + sex + ", 班级=" + banji + "]";
42     }
43     
44     
45 
46 }
 1 <%@page import="com.sp.test.Student"%>
 2 <%@ page language="java" contentType="text/html; charset=UTF-8"
 3     pageEncoding="UTF-8"%>
 4 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 5 <html>
 6 <head>
 7 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 8 <title>Insert title here</title>
 9 </head>
10 <body>
11 <%
12 Student st = new Student("张三",2016001,"男","网络工程");
13 out.println(st.toString());
14 
15 %>
16 </body>
17 </html>

 

posted @ 2016-07-01 08:33  唐枫  阅读(2690)  评论(0编辑  收藏  举报