JAVA菜鸟关于类互相引用问题
package com.example.model;
import java.util.*;
public class BeerExpert{
public List getBrands(String color){
List brands = new ArrayList();
if (color.equals("amber")){
brands.add("Jack Amber");
brands.add("Red Moose");
}else{
brands.add("Jail Pale Ale");
brands.add("Gout stout");
}
return(brands);
}
}
package com.example.web;
//import com.example.model.*;
import com.example.model.BeerExpert;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class BeerSelect extends HttpServlet{
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException,ServletException{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("Beer Selection Advice<br>");
String c = request.getParameter("color");
BeerExpert be = new BeerExpert();
List result = be.getBrands(c);
Iterator it = result.iterator();
while(it.hasNext()){
out.println("<br>try: " + it.next());
}
}
}