Hi,
When I compile the .java file from the book, I get a "cannot resolve symbol". It point to the bean file.
BankCustomer.java
------------------------------
package coreservlets;
import java.util.*;
public class BankCustomer {
private String id, firstName, lastName;
private double balance;
public BankCustomer(String id, String firstName, String lastName, double balance) {
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
this.balance = balance;
}
public String getId() {
return(id);
}
public String getFirstName() {
return(firstName);
}
public String getLastName() {
return(lastName);
}
public double getBalance() {
return(balance);
}
public double getBalanceNoSign() {
return(Math.abs(balance));
}
public void setBalance(double balance) {
this.balance = balance;
}
private static HashMap customers;
static {
customers = new HashMap();
customers.put("id001", new BankCustomer("id001", "John", "Hacker", -3456.78));
customers.put("id002", new BankCustomer("id002", "Jane", "Hacker", 1234.56));
customers.put("id003", new BankCustomer("id003", "Juan", "Hacker", 987654.32));
}
public static BankCustomer getCustomer(String id) {
return((BankCustomer)customers.get(id));
}
}
------------------------------
ShowBalance.java
------------------------------
package coreservlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ShowBalance extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
BankCustomer customer = BankCustomer.getCustomer(request.getParameter("id")); //error out when using BankCustomer
String address;
if (customer == null) {
address = "/WEB-INF/bank-account/UnknownCustomer.jsp";
} else if (customer.getBalance() < 0) {
address = "/WEB-INF/bank-account/NegativeBalance.jsp";
request.setAttribute("badCustomer", customer);
} else if (customer.getBalance() < 10000) {
address = "/WEB-INF/bank-account/NormalBalance.jsp";
request.setAttribute("regularCustomer", customer);
} else {
address = "/WEB-INF/bank-account/HighBalance.jsp";
request.setAttribute("eliteCustomer", customer);
}
RequestDispatcher dispatcher =
request.getRequestDispatcher(address);
dispatcher.forward(request, response);
}
}
------------------------------
Thanks and I am sorry if this is a simple error. I tried to set the ClassPath and still did not work. I am using Apache Tomcat 5.5.
Clark
When I compile the .java file from the book, I get a "cannot resolve symbol". It point to the bean file.
BankCustomer.java
------------------------------
package coreservlets;
import java.util.*;
public class BankCustomer {
private String id, firstName, lastName;
private double balance;
public BankCustomer(String id, String firstName, String lastName, double balance) {
this.id = id;
this.firstName = firstName;
this.lastName = lastName;
this.balance = balance;
}
public String getId() {
return(id);
}
public String getFirstName() {
return(firstName);
}
public String getLastName() {
return(lastName);
}
public double getBalance() {
return(balance);
}
public double getBalanceNoSign() {
return(Math.abs(balance));
}
public void setBalance(double balance) {
this.balance = balance;
}
private static HashMap customers;
static {
customers = new HashMap();
customers.put("id001", new BankCustomer("id001", "John", "Hacker", -3456.78));
customers.put("id002", new BankCustomer("id002", "Jane", "Hacker", 1234.56));
customers.put("id003", new BankCustomer("id003", "Juan", "Hacker", 987654.32));
}
public static BankCustomer getCustomer(String id) {
return((BankCustomer)customers.get(id));
}
}
------------------------------
ShowBalance.java
------------------------------
package coreservlets;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class ShowBalance extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
BankCustomer customer = BankCustomer.getCustomer(request.getParameter("id")); //error out when using BankCustomer
String address;
if (customer == null) {
address = "/WEB-INF/bank-account/UnknownCustomer.jsp";
} else if (customer.getBalance() < 0) {
address = "/WEB-INF/bank-account/NegativeBalance.jsp";
request.setAttribute("badCustomer", customer);
} else if (customer.getBalance() < 10000) {
address = "/WEB-INF/bank-account/NormalBalance.jsp";
request.setAttribute("regularCustomer", customer);
} else {
address = "/WEB-INF/bank-account/HighBalance.jsp";
request.setAttribute("eliteCustomer", customer);
}
RequestDispatcher dispatcher =
request.getRequestDispatcher(address);
dispatcher.forward(request, response);
}
}
------------------------------
Thanks and I am sorry if this is a simple error. I tried to set the ClassPath and still did not work. I am using Apache Tomcat 5.5.
Clark