-1

主程序

package esss;
// Add
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import esss.DBI;
import esss.Shared;
import esss.Control;



public class deduction extends esss.Control {
protected DBI dbi;

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
  HttpSession session = request.getSession();
  esss.Shared bean = (esss.Shared)session.getAttribute("shared");

  //String[] checked = request.getParameter("deduction");// needs parameter
  String type = request.getParameter("deduction");// needs parameter
  String amount = request.getParameter("amount");

  addDeduction(bean, type, amount);
  gotoPage("/mainPage.jsp", request, response);
}

public void addDeduction(esss.Shared bean,String type, String amount) throws ServletException{
  try {
    dbi = new esss.DBI();
    if(dbi.connect()) {
      String payment ="";
      if(type.equals("Parking Lot A")) {
        payment="10";
      }
      else if(type.equals("Parking Lot B")) {
        payment="5";
      }
      else if(type.equals("Extra Life Insurance(Age<35, 50,000)")) {
        payment="5";
      }
      else if(type.equals("Extra Life Insurance(Age 35-55, 25,000)")) {
        payment="17";
      }
      else if(type.equals("Extra Life Insurance(Age>55, 10,000)")) {
        payment="35";
      }

      if(!(type.equals("none"))) {
        String empId= bean.getEmpId();
        String dedDate = bean.getCurrentDate();
        //String dedId = bean.getdedId();
        //String dedname = bean.getdedName();
        //String dedAmount = bean.getAmount();
        dbi.updateDeduction(empId,dedId, dedName, type,dedDate);
        bean.setMessage("Deduction Added");
      }
      else {
        bean.setMessage("Please make sure you perfrom deduction");
      }
      dbi.close();
    }
    }catch(Exception e) {
      e.printStackTrace();
      bean.setMessage("Exception caught : " + e);
      bean.setError("The database could not be connected");
    }
  }
}

编译器错误

compile:
[javac] Compiling 22 source files to /home/student/mcintron/cps4931/maricarmen/build/WEB-INF/classes
[javac] /home/student/mcintron/cps4931/maricarmen/src/deduction.java:71: cannot find symbol
[javac] symbol  : variable dedId
[javac] location: class esss.deduction
[javac]                     dbi.updateDeduction(empId,dedId, dedName, type,dedDate);
[javac]                                               ^
[javac] /home/student/mcintron/cps4931/maricarmen/src/deduction.java:71: cannot find symbol
[javac] symbol  : variable dedName
[javac] location: class esss.deduction
[javac]                     dbi.updateDeduction(empId,dedId, dedName, type,dedDate);
[javac]                                                      ^
[javac] 2 errors

BUILD FAILED

这是主要代码,当我使用编译器进行编译时,它给了我错误。我不明白为什么它会显示这个错误?

4

2 回答 2

0

你没有声明这两个变量,对吧?

在行中:

 dbi.updateDeduction(empId,dedId, dedName, type,dedDate);

dedId和_dedName

所以你需要取消注释它们......仔细看,就在上面。我猜可能还有另一个问题。一般来说,如果它说它找不到 XYZ,这意味着它甚至没有被声明

于 2013-01-11T05:25:07.577 回答
0

dedId没有声明,我可以在注释中找到下面的行,如果你可以取消注释你的代码或下面的行它可能会编译。

  //String dedId = bean.getdedId();
  //String dedname = bean.getdedName();

替换这个

//String dedId = bean.getdedId();
//String dedname = bean.getdedName();

有了这个

 String dedId = bean.getdedId();
 String dedname = bean.getdedName();
于 2013-01-11T05:26:42.897 回答