Hi,
I am practicing Head First
Servlets and JSPs at the moment in
progress to my scwcd certification. I am struck in compiling
java file residing in the same directory structure.
I have a BeerExpert_model.class file in the directory
com.example.beermodel
and
BeerSelect.class file in the directory com.example.beer.
BeerSelect.class calls BeerExpert_model class. But the package,
com.example.beermodel isn't being recognised while compiling
BeerSelect.class.
I have copied both these classes below:
BeerSelect.java:
package com.example.beer;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import com.example.beermodel.BeerExpert_model;
import java.util.*;
public class BeerSelect extends HttpServlet
{
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
String str = request.getParameter("color");
//out.println("<br>Get Beer Color "+str);
BeerExpert_model bem = new BeerExpert_model();
List result = bem.getBrands(str);
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("Beer Selection Advice<br>");
Iterator it = result.iterator();
while(it.hasNext())
{
out.print("<br> try"+it.next());
}
}
}
BeerExpert_model.java:
package com.example.beermodel;
import java.util.*;
public class BeerExpert_model
{
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);
}
}
Please help me resolve this.
Thanks and regards,
Diana