最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
javabean组件在jsp页面中的应用方法
时间:2011-04-20 编辑:简简单单 来源:一聚教程网
javabean组件在jsp教程页面中的应用方法
一,bean技术基础
1)jsp:usebean
构建一个新的bean。例如:
等价于下列jsp语句----
<% coreservlets.book book1 = new coreservlets.book(); %>
2)jsp:getproperty
读取或者输出bean属性的值。例如:
等价于---
<%= book1.gettitle() %>
3)jsp:setproperty
修改bean的属性。例如:
等价于----
<% book1.settitle("core servlets and javaserver pages"); %>
用这三种方式来操作bean,对于不熟悉java编程的web设计人员来说,是有益的。
二,共享bean
package tax;
public class taxrate {
string product;
double rate;
public taxrate() {
this.product = "a001 ";
this.rate = 5;
}
public void setproduct (string productname) {
this.product = productname;
}
public string getproduct() {
return (this.product);
}
public void setrate (double ratevalue) {
this.rate = ratevalue;
}
public double getrate () {
return (this.rate);
}
}
在 jsp 页面中应用上述 bean 要用到 < jsp:usebean> 标记。依赖于具体使用的 jsp 引擎的不同,在何处配置以及如何配置 bean 的方法也可能略有不同。本文将这个 bean 的 .class 文件放在 c:.0inf目录下,这里的 tax 是一个专门存放该 bean 的目录。下面是一个应用上述 bean 的示例页面:
< html>
< body>
< %@ page language= "java " %>
< jsp:usebean id= "taxbean " scope= "application " class= "tax.taxrate " />
< % taxbean.setproduct( "a002 ");
taxbean.setrate(17);
%>
使用方法 1 : < p>
产品 : < %= taxbean.getproduct() %> < br>
税率 : < %= taxbean.getrate() %>
< p>
< % taxbean.setproduct( "a003 ");
taxbean.setrate(3);
%>
< b> 使用方法 2 : < /b> < p>
产品 : < jsp:getproperty name= "taxbean " property= "product " />
< br>
税率 : < jsp:getproperty name= "taxbean " property= "rate " />
< /body>
< /html>
-
上一个: JSP页面编码问题分析
-
下一个: java连接db2数据代码
相关文章
- webpack打包单页面如何引用的js 06-07
- angular.js 路由及页面传参示例 05-03
- 在js代码拼接dom对象到页面上去的模板总结 04-05
- jsp、struts、spring、mybatis实现前端页面功能模块化拆分的方案 01-11
- JS实现的表头列头固定页面功能示例 01-10
- JS调用iframe方式实现Web区域打印页面内容 01-23