在'Salary.CalSalary'类型的bean中找不到关于属性'tax'的任何信息?

时间:2015-07-25 18:44:39

标签: java jsp

<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;
    }

}

请建议我,我哪里出错了?

1 个答案:

答案 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;

 }

您可以在此处查看命名约定:

Naming convention for getters/setters in Java