<html>
<body>
<jsp:useBean id="s" class="Salary.CalSalary"scope="page"/>
<jsp:setProperty name="s" property="sal" param="salary"/>
<%
s.getTax();
%>
<jsp:getProperty name="s" property= "tax"/>
</body>
CalSalary.java
import java.io.*;
public class CalSalary implements Serializable{
private double tax,sal;
public CalSalary()
{
tax=0;
sal=0;
}
public void setSal(int sal1)
{
sal=sal1;
}
public double returnTax()
{
return tax;
}
public void getTax()
{
tax=sal*15/100;
}
}
请建议我,我哪里出错了?
答案 0 :(得分:0)
您的java类getter和setter必须遵循java bean标准。所以,在课堂上试试这个:
public void setSal(double sal1){
sal=sal1;
}
public double getSal(){
return sal;
}
public void setTax(double tax){
this.tax = tax;
}
public double getTax(){
tax=sal*15/100;
return tax;
}
您可以在此处查看命名约定: