<%--指定所使用的为Java语言,并输入tax包--%>
<%@ page language="java" import="tax.TaxRate" contentType="text/html" %>
<HTML>
<BODY>
<%--对Bean的设置,并生成一个实例--%>
<jsp:useBean id="TaxRate" scope="request" class="tax.TaxRate"/><table width="780" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><%--使用Beans的方法获取或者设置Beans属性--%>
<p>用Beans方法修改:</p>
<p>修改前<br>
<%--使用Beans的getProduct()和getRate()法获取Beans属性--%>
产品:<%= TaxRate.getProduct() %><br>
税率:<%= TaxRate.getRate() %></p>
<p>
<%--用Beans的setProduct()和setRate()设置Beans属性--%>
<%
TaxRate.setProduct("A002");
TaxRate.setRate(17);
%>
修改后
<%--用Beans的getProduct()和getRate()设置Beans属性--%>
</p>
<p>产品:<%= TaxRate.getProduct() %><br>
税率:<%= TaxRate.getRate() %>
<% TaxRate.setProduct("A003");
TaxRate.setRate(25); %>
</p></td>
<td> <p>
<%--用Beans的setProduct()和setRate()设置Beans属性--%>
<%
TaxRate.setProduct("A003");
TaxRate.setRate(25);
%>
<%--使用JSP指令获取或者设置Beans属性--%>
</p>
<p>用<jsp:getProperty>和<jsp:setProperty>修改</p>
<p>修改前:<br>
<%--得到Beans的属性--%>
产品:<jsp:getProperty name="TaxRate" property="Product" /><br>
税率:<jsp:getProperty name="TaxRate" property="Rate" /></p>
<%--对Beans属性的重新设置--%>
<jsp:setProperty name="TaxRate" property="Product" value="A004" />
<jsp:setProperty name="TaxRate" property="Rate" value="29" />
<p> </p>
<p>修改后:<br>
<%--得到Beans的属性--%>
产品:<jsp:getProperty name="TaxRate" property="Product" /><br>
税率:<jsp:getProperty name="TaxRate" property="Rate" /></p>
</td>
</tr>
</table>
<p> </p>
<p> </p>
<p> </p>
</BODY>
</HTML>
=================
以上是TaxRate.jsp,调用一个javabean,包tax中的TaxRate类,代码如下:
package tax;public class TaxRate { // Fields
String Product;
double Rate; // Constructors
public TaxRate() { } // Methods
public void setProduct(String string) { }
public String getProduct() { return null;}
public void setRate(double _double) { }
public double getRate() { return 0.0;}
}
==============================
已经编译成功,但是运行http://localhost:8080/jsp/TaxRate.jsp总有错误:
HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Cannot find any information on property 'Product' in a bean of type 'tax.TaxRate'
at org.apache.jasper.runtime.JspRuntimeLibrary.getReadMethod(JspRuntimeLibrary.java:650)
at org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:652)
at org.apache.jasper.compiler.Node$GetProperty.accept(Node.java:507)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:983)
at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:1025)
at org.apache.jasper.compiler.Node$Visitor.visit(Node.java:1031)下面还有一些错误信息,不知道怎么改?
<%@ page language="java" import="tax.TaxRate" contentType="text/html" %>
<HTML>
<BODY>
<%--对Bean的设置,并生成一个实例--%>
<jsp:useBean id="TaxRate" scope="request" class="tax.TaxRate"/><table width="780" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><%--使用Beans的方法获取或者设置Beans属性--%>
<p>用Beans方法修改:</p>
<p>修改前<br>
<%--使用Beans的getProduct()和getRate()法获取Beans属性--%>
产品:<%= TaxRate.getProduct() %><br>
税率:<%= TaxRate.getRate() %></p>
<p>
<%--用Beans的setProduct()和setRate()设置Beans属性--%>
<%
TaxRate.setProduct("A002");
TaxRate.setRate(17);
%>
修改后
<%--用Beans的getProduct()和getRate()设置Beans属性--%>
</p>
<p>产品:<%= TaxRate.getProduct() %><br>
税率:<%= TaxRate.getRate() %>
<% TaxRate.setProduct("A003");
TaxRate.setRate(25); %>
</p></td>
<td> <p>
<%--用Beans的setProduct()和setRate()设置Beans属性--%>
<%
TaxRate.setProduct("A003");
TaxRate.setRate(25);
%>
<%--使用JSP指令获取或者设置Beans属性--%>
</p>
<p>用<jsp:getProperty>和<jsp:setProperty>修改</p>
<p>修改前:<br>
<%--得到Beans的属性--%>
产品:<jsp:getProperty name="TaxRate" property="Product" /><br>
税率:<jsp:getProperty name="TaxRate" property="Rate" /></p>
<%--对Beans属性的重新设置--%>
<jsp:setProperty name="TaxRate" property="Product" value="A004" />
<jsp:setProperty name="TaxRate" property="Rate" value="29" />
<p> </p>
<p>修改后:<br>
<%--得到Beans的属性--%>
产品:<jsp:getProperty name="TaxRate" property="Product" /><br>
税率:<jsp:getProperty name="TaxRate" property="Rate" /></p>
</td>
</tr>
</table>
<p> </p>
<p> </p>
<p> </p>
</BODY>
</HTML>
=================
以上是TaxRate.jsp,调用一个javabean,包tax中的TaxRate类,代码如下:
package tax;public class TaxRate { // Fields
String Product;
double Rate; // Constructors
public TaxRate() { } // Methods
public void setProduct(String string) { }
public String getProduct() { return null;}
public void setRate(double _double) { }
public double getRate() { return 0.0;}
}
==============================
已经编译成功,但是运行http://localhost:8080/jsp/TaxRate.jsp总有错误:
HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: Cannot find any information on property 'Product' in a bean of type 'tax.TaxRate'
at org.apache.jasper.runtime.JspRuntimeLibrary.getReadMethod(JspRuntimeLibrary.java:650)
at org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:652)
at org.apache.jasper.compiler.Node$GetProperty.accept(Node.java:507)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:983)
at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:1025)
at org.apache.jasper.compiler.Node$Visitor.visit(Node.java:1031)下面还有一些错误信息,不知道怎么改?
解决方案 »
- java中String类型和int类型转换
- 判断td在table中的行数
- seasar mavne2
- org.xml.sax.SAXParseException:src-import.0:阅读导入模式文档"null"失败.该异常如何处理呀??
- ............建站规划! 站点一般要怎样建文件夹才合理?.............
- 请问http协议中的Content-Transfer-Encoding:8bit,该怎样理解?针对Transfer-Encoding该对我的http消息做什么处理?
- 怎么实现jsp动态页面转成静态页面,并实现更新功能??
- 它到底告诉我????(JSP调试)
- 如何禁止jsp页面自己刷新(实在没有分了)
- spring的aspect配置找不到错了。。。麻烦帮忙看看可以吗
- [Tomcat配置] 不想在浏览器中输入IP或http://localhost,局域网内直接输入http;//newName就可以访问,在怎么配置?
- 求助如何在JSP里显示EXCEL
首先Product没有实例化,应该String Product = new String();
其次,方法public void setProduct(String str){ this.product = str;} 应该这样写
最后,你的bean只是拿来练习吧?作用不大~~呵呵~
//Bean生成
//指明tax的包
package tax;
//创建TaxRate的类
public class TaxRate
{
//指明变量Product和Rate的类型
String Product;
double Rate; //TaxRate类的构造器
public TaxRate()
{
Product="A001";
Rate=5;
}
//TaxRate类的setProduct方法
public void setProduct(String ProductName)
{
this.Product=ProductName;
}
//TaxRate类的getProduct方法
public String getProduct()
{
return(this.Product);
} //TaxRate类的setRate方法
public void setRate(double rateValue)
{
this.Rate=rateValue;
} //TaxRate类的getRate方法
public double getRate()
{
return (this.Rate);
}}
//Bean生成结束
{
//指明变量Product和Rate的类型
String Product;
double Rate;
/////////////////////////////////
您是说这里吗?
{
//指明变量Product和Rate的类型
String Product;
double Rate;
/////////////////////////////////
改成以下吗?
/////////////////////////////////
public class TaxRate
{
//指明变量Product和Rate的类型
String product;
double rate;