日期:2014-05-19 浏览次数:20744 次
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>