my dog learned polymorphism*
The moose likes Beginning Java and the fly likes Head First Servlets & JSP: Can't compile second version of BeerSelect.java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Head First Servlets & JSP: Can Watch "Head First Servlets & JSP: Can New topic
Author

Head First Servlets & JSP: Can't compile second version of BeerSelect.java

David Schwartz
Greenhorn

Joined: May 28, 2008
Posts: 10
I was wondering if anyone could help me out. I was trying to compile BeerSelect.java after following all steps on page 84 of HFSJ book.
I have exactly the same sub-directory structure and etc.
and i am getting 3 erros by the compiler:
1)package com.example.model does not exist...
2)cannot find symbol class ^BeerExpert... BeerExpert beer = new BeerExpert();
3)cannot find symbol class BeerExpert... BeerExpert beer = new ^BeerExpert();
Below I have included all the JAVA code.
thank you,


David

Here is the code for BeerSelect.java
package com.example.web;

//VERY IMPORTANT
import com.example.model.*;
//import com.example.web.*;
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 {
// insterted the line below
PrintWriter out = response.getWriter();
String c = request.getParameter("color");

System.out.println("<br>Gor beer color " + c);
BeerExpert beer = new BeerExpert();
List result = beer.getBrands(c);

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());
}
}
}
Here is the code for BeerExpert.java
package com.example.model;
//Inserted this line
//import com.example.web.*;
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);
}

}
David Schwartz
Greenhorn

Joined: May 28, 2008
Posts: 10
P.S. Sorry here is the command line to compile BeerSelect.java

c:\study\beerV1>javac -classpath c:\tomcat\common\lib\servlet-api.jar;classes:. -d classes c:\study\beerV1\src\com\example\web\BeerSelect.java

Here is the command line which I successfully used to compile BeerExpert.java

c:\study\beerV1>javac -classpath c:\tomcat\common\lib\servlet-api.jar;classes:. -d classes c:\study\beerV1\src\com\example\model\BeerExpert.java
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38508
    
  23
Welcome to JavaRanch.
Well done working out how to compile the class; it would appear there was a dependency in the classpath.
David Schwartz
Greenhorn

Joined: May 28, 2008
Posts: 10
yes, i understand that there was a dependency.
that is why i 1st had to compile (successfully) BeerExpert.java
The only problem is BeerSelect.java does not compile
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38508
    
  23
Sorry. I didn't realise. What compiler errors are you getting? I am not familiar with that book. Do they give any instructions for downloading any other resources?
David Schwartz
Greenhorn

Joined: May 28, 2008
Posts: 10
i am getting 3 erros by the compiler:
1)package com.example.model does not exist...
2)cannot find symbol class ^BeerExpert... BeerExpert beer = new BeerExpert();
3)cannot find symbol class BeerExpert... BeerExpert beer = new ^BeerExpert();
Rodrigo Tomita
Ranch Hand

Joined: Apr 28, 2008
Posts: 70
David,

It seems you are mixing ; and : in your classpath (as path separators)... I think it is ; for Windows and : for Unix/Linux. So the compiler might be getting lost on the classes and . folders.

Hope it helps.
[ May 29, 2008: Message edited by: Rodrigo Tomita ]
David Schwartz
Greenhorn

Joined: May 28, 2008
Posts: 10
yes, thank you very much!
it compiled and created the appropriate class file.
I was indeed doing it under windows which means i had to use ';' throughout and not mix it up with Unix Shell's ':'
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Head First Servlets & JSP: Can't compile second version of BeerSelect.java