欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

JSP JavaBean的setProperty属性

程序员文章站 2024-02-15 21:38:34
1.包: 复制代码 代码如下: package paintbrush; /** * * @author lucifer */ public class paintbrush...
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