1. 程式人生 > >jsp呼叫javaBean方式一(new例項化物件)

jsp呼叫javaBean方式一(new例項化物件)

   1:javabean

package cn.mldn.lxh.demo;

/**
 * javaBean 留給JSP呼叫
 * 
 * @author Administrator
 * 
 */
public class SimpleBean {
private String name;
private int age;
private char sex;
private String degree;


public SimpleBean(String name, int age, char sex, String degree) {
this.name = name;
this.age = age;
this.sex = sex;
this.degree = degree;
}


public String toString() {
return "姓名:" + this.name + "<br>年齡:" + this.age + "<br>性別:" + this.sex
+ "<br>學歷:" + this.degree;
}


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 char getSex() {
return sex;
}


public void setSex(char sex) {
this.sex = sex;
}


public String getDegree() {
return degree;
}


public void setDegree(String degree) {
this.degree = degree;
}

}

  2:jsp

<%@ page contentType="text/html" language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="cn.mldn.lxh.demo.SimpleBean" %>
<!DOCTYPE HTML >
<html>
  <head>
    <title>JSP呼叫javaBean</title>
  </head>
  <body>
  <%
  SimpleBean simple=new SimpleBean("張三",23,'男',"大學本科");
   %>
   <h3><%=simple%></h3>
  </body>
</html>