• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Compiling problems

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic