1. JSP网页
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
<%@page import="com.example.bean.Person"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!
DOCTYPE
html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<
html
>
<
head
>
<
meta
http-equiv="Content-Type" content="text/html; charset=UTF-8">
<
title
>JavaBean的使用</
title
>
</
head
>
<
body
>
<
jsp:useBean
id="person" class="com.example.bean.Person"></
jsp:useBean
>
<
jsp:getProperty
property="name" name="person" /><
br
>
<
jsp:getProperty
property="age" name="person" /><
br
>
<
jsp:getProperty
property="address" name="person"/><
br
>
<
jsp:setProperty
property="name" name="person" value="lisi"/>
<
jsp:getProperty
property="name" name="person" /><
br
>
<%= person.getName() %>
</
body
>
</
html
>
|
2. Person类
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
package
com.example.bean;
public
class
Person {
private
String name =
"zhangsan"
;
private
int
age =
10
;
private
String address =
"beijing"
;
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 getAddress() {
return
address;
}
public
void
setAddress(String address) {
this
.address = address;
}
}
|
3 .显示效果
本文转自Work Hard Work Smart博客园博客,原文链接:http://www.cnblogs.com/linlf03/p/7670670.html,如需转载请自行联系原作者