惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
T
Threatpost
阮一峰的网络日志
阮一峰的网络日志
美团技术团队
F
Fortinet All Blogs
The GitHub Blog
The GitHub Blog
月光博客
月光博客
V
Visual Studio Blog
T
Tailwind CSS Blog
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
Jina AI
Jina AI
J
Java Code Geeks
Martin Fowler
Martin Fowler
大猫的无限游戏
大猫的无限游戏
Recorded Future
Recorded Future
C
Check Point Blog
腾讯CDC
N
Netflix TechBlog - Medium
aimingoo的专栏
aimingoo的专栏
罗磊的独立博客
Hacker News: Ask HN
Hacker News: Ask HN
SecWiki News
SecWiki News
博客园 - Franky
Hacker News - Newest:
Hacker News - Newest: "LLM"
N
News | PayPal Newsroom
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Security @ Cisco Blogs
W
WeLiveSecurity
The Last Watchdog
The Last Watchdog
Cloudbric
Cloudbric
F
Full Disclosure
The Cloudflare Blog
Y
Y Combinator Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
S
Schneier on Security
Schneier on Security
Schneier on Security
Spread Privacy
Spread Privacy
L
LINUX DO - 热门话题
AI
AI
N
News and Events Feed by Topic
T
Tor Project blog
P
Palo Alto Networks Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
G
Google Developers Blog

博客园 - 千年寒冰

C# 操作Excel大全 Wince 或Windows平台 C#调用Bitmap对象后资源应该如何释放 Window7+vs2008+QT环境搭建 基于三汇语音卡的呼叫中心开发--(一) 解决NTLDR is missing,系统无法启动的方法 mssql charindex 美化表单 屏幕取字原理 jsp web项目开发详述 jsp request 对象详解 博文阅读密码验证 - 博客园 WML教程9:Select List 控件 jsp的session介绍 (转) 想一想 javabean :类与函数调用(数据库访问类) JSP中的pageEncoding和contentType属性(转) javabean在jsp中的调用(原创) 远程连接SQL Server (转) 三天学好ADO(转)
jsp调用javabean实例
千年寒冰 · 2007-08-31 · via 博客园 - 千年寒冰

jsp调用javabean实例 goodsbean.java

package sale;
public class goodsbean{
    String Product;
    double Price;
    public goodsbean (){
    this.Product = "box";
    this.Price = 5.0;
    }
public void setProduct (String ProductName){
    this.Product = ProductName;
}
public String getProduct(){
    return (this.Product);
}
public void setPrice (double priceValue){
    this.Price = priceValue;
}
public double getPrice(){
    return (this.Price);
}
}

编译完生成的.class文件,放到:Tomcat 5.5\webapps\ROOT\WEB-INF\classes\sale 目录下。

调用方法:

<%@ page contentType="text/html;charset=GB2312"%>
<%//request.setCharacterEncoding("iso_8859_1");%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>goodsbean</title>
</head>

<body>

<jsp:useBean id="goodsbean" scope="application" class="sale.goodsbean" />
<%
goodsbean.setProduct("clock");
goodsbean.setPrice(17);
%>
使用方法1:
产品:<%= goodsbean.getProduct()%><br>
税率:<%= goodsbean.getPrice()%>

<%goodsbean.setProduct("chair");
goodsbean.setPrice(3);
%>
<br>使用方法2:
产品:<jsp:getProperty name="goodsbean" property = "Product" />
<br>
税率:<jsp:getProperty name="goodsbean" property = "Price" />

</body>
</html>

注意:设置bean的属性如下

<jsp:setProperty name="goodsbean" property = "Product"   value="asdf"/>
<jsp:setProperty name="goodsbean" property = "Price" value="adad" />

posted @ 2007-08-31 16:35  千年寒冰  阅读(9448)  评论()    收藏  举报