JSP JavaBean的setProperty属性

编程学习 2021-07-05 11:23www.dzhlxh.cn编程入门
JSP JavaBean的setProperty属性使用实例。
1.包:
代码如下:

package PaintBrush;
/**
*
* @author lucifer
*/
public class PaintBrush {
private String curcolor = "red";
public String getColor(){
return curcolor;
}
public void setColor(String color){
curcolor = color;
}
}

2.JSP代码:
代码如下:

<%--
Document : TestSetPro
Created on : 2009-10-3, 15:02:50
Author : lucifer
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="brush" class="PaintBrush.PaintBrush"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
Original Color:
<jsp:getProperty name="brush" property="color"/>
<br>
Changed Color:
<jsp:setProperty name="brush" property="color" value="blue"/>
<jsp:getProperty name="brush" property="color"/>
</body>
</html>

3.输出:
Original Color: red
Changed Color: blue

Copyright © 2016-2025 www.dzhlxh.cn 金源码 版权所有 Power by

网站模板下载|网络推广|微博营销|seo优化|视频营销|网络营销|微信营销|网站建设|织梦模板|小程序模板