程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> JAVA綜合教程 >> javaBean 練習—封裝學生信息,javabean封裝

javaBean 練習—封裝學生信息,javabean封裝

編輯:JAVA綜合教程

javaBean 練習—封裝學生信息,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>

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved