Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
David Schwartz
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49405
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49405
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ':'
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic