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
复制代码 代码如下:
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
上一篇: python 多进程全局变量
下一篇: JSP 中文字符处理代码