• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Compiling problems

 
Timothy Eric
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me start off by thanking you all in advance.

I am trying to get started with learning JSP. I have purchased the Head First Servlets & JSP book by Basham, Sierra, & Bates. In following the example i have come across an issue that is preventing me from progressing in my learning. Basically i have created two classes and packaged them as such:

BeerExpert.java (com.example.model)
BeerSelect.java (com.example.web)

Both packages reside under the same folder "/src"

I am able to compile my BeerExpert code, but not BeerSelect. The following is the code for both of my classes:

package com.example.web;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import com.example.model.*;

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");

out.println("<br>Got beer color " + c);
BeerExpert be = new BeerExpert();
List result = be.getBrands(c);
Iterator it = result.iterator();

while(it.hasNext()) {
out.print("<br>try: " + it.next());
}
}

}


package com.example.model;

import java.util.*;

public class BeerExpert {

public List getBrands(String color) {

List<String> brands = new ArrayList<String>();
if (color.equals("amber")) {
brands.add("Jack Amber");
brands.add("San Miguel");
}
else if (color.equals("light")) {
brands.add("Corona Special Light");
brands.add("Michelob Ultra Light");
brands.add("Budweiser Select");
}
else if (color.equals("brown")) {
brands.add("Newcastle Brown Ale");
brands.add("Dos Equis");
}
else {
brands.add("Guinness");
}
return(brands);
}
}


Here is the error i receive when trying to compile the BeerSelect.java code:

C:\MyProjects\beer>javac -d classes src\com\example\web\BeerSelect.java
src\com\example\web\BeerSelect.java:9: package com.example.model does not exist
import com.example.model.*;
^
src\com\example\web\BeerSelect.java:21: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be = new BeerExpert();
^
src\com\example\web\BeerSelect.java:21: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.BeerSelect
BeerExpert be = new BeerExpert();
^
3 errors

C:\MyProjects\beer>



Please help me. I am running Tomcat 5.5.12 and have JDK1.5.0_05 installed.

 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The directory which contains the two packages needs to be on your classpath.
See: http://faq.javaranch.com/view?HowToSetTheClasspath
for help with classpaths.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic