java Bean里面的代码 问题 谢谢大家啊 为什么jsp里面用param ="discount" 就没错 用value="<%= request.getParameter("discount")%>" 就会报异常rg.apache.jasper.JasperException: An exception occurred processing JSP page /bean/testproperty.jsp 搞了一个早上发现用param才行 package Bean;public class SaleEntry {
private double discount = 1.0;
private String productname = "unknown";
private int number = 0;
public double getDiscount() {
return discount;
}
public void setDiscount(double discount) {
this.discount = discount;
}
public String getProductname() {
return productname;
}
public void setProductname(String productname) {
if(productname!=null){
this.productname = productname;
} else {
this.productname = "unknown";
}
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public double productcost(){
double cost;
if(productname.equals("coffee")){
cost = 13.14*this.getDiscount();
} else{
cost = 0;
}
return roundmoney(cost);
}
public double roundmoney(double cost){
return Math.floor((cost*100)/100.0);//将小数点后面的内容给去掉
}
public double gettotalcost(){
return (this.productcost()*this.getNumber());
}
}
jsp代码
<html>
<head>
<title>jsp set property</title>
</head>
<body>
<jsp:useBean id="se" class="Bean.SaleEntry"/>
<jsp:setProperty
name="se"
property="productname"
value="<%= request.getParameter("productname")%>"/>
<jsp:setProperty
name="se"
property="discount"
param ="discount" />
<!--value="<%= request.getParameter("discount")%>" />-->
<table align="center" border="2"><tr >
<th>product name <th> number <th> discount <th> totalcost
</tr>
<td><jsp:getProperty name="se" property="productname" />
</tr>
</table>
</body>
</html>
private double discount = 1.0;
private String productname = "unknown";
private int number = 0;
public double getDiscount() {
return discount;
}
public void setDiscount(double discount) {
this.discount = discount;
}
public String getProductname() {
return productname;
}
public void setProductname(String productname) {
if(productname!=null){
this.productname = productname;
} else {
this.productname = "unknown";
}
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public double productcost(){
double cost;
if(productname.equals("coffee")){
cost = 13.14*this.getDiscount();
} else{
cost = 0;
}
return roundmoney(cost);
}
public double roundmoney(double cost){
return Math.floor((cost*100)/100.0);//将小数点后面的内容给去掉
}
public double gettotalcost(){
return (this.productcost()*this.getNumber());
}
}
jsp代码
<html>
<head>
<title>jsp set property</title>
</head>
<body>
<jsp:useBean id="se" class="Bean.SaleEntry"/>
<jsp:setProperty
name="se"
property="productname"
value="<%= request.getParameter("productname")%>"/>
<jsp:setProperty
name="se"
property="discount"
param ="discount" />
<!--value="<%= request.getParameter("discount")%>" />-->
<table align="center" border="2"><tr >
<th>product name <th> number <th> discount <th> totalcost
</tr>
<td><jsp:getProperty name="se" property="productname" />
</tr>
</table>
</body>
</html>
解决方案 »
- jsp如何将图片路径存入数据库
- ProxyFactoryBean AOP问题
- char和255这个数字的关系,255这个数字是不是可以判断是字符还是字母。char=255什么?
- 想要一个通用的jsp页面注册模块输入框的判断代码,最好是直接传入form来判断的那种?
- 在线等,load()异常,解决了一天了.....555555555555
- java 怎么记录用户操作
- 一条SQL语句的困惑???.....
- java.sql.SQLException: Io 异常: The Network Adapter could not establish the connec
- 组件“struts-config”在此不允许“message-resources”。这个算什么错误,错误在哪里呢??
- Linux下的Eclipse要在图形界面进入系统才能启动吗?
- hibernate映射表的问题
- jsp中的参数传给struts2中action的方法
改成 value='<%= request.getParameter("productname")%>'
使用这个的话那这个参数是从哪个页面跳转过来的呢?
value="<%= request.getParameter(\"discount\")%>"编译就能通过了!!
即将request.getParameter("discount"))返回的字符串类型转换成double类型即可:
value="<%= request.getParameter("discount")%>"改写成
value="<%=Double.parseDouble(request.getParameter(\"discount\"))%>" ,我这边实验通过了,希望对您有帮助!