aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Ch3 Excercise in HFJS Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Ch3 Excercise in HFJS" Watch "Ch3 Excercise in HFJS" New topic
Author

Ch3 Excercise in HFJS

Jane Joseph
Ranch Hand

Joined: Feb 21, 2008
Posts: 39
Hi,

My java program locations are as follows:
BeerSelect\src\com\example\model\BeerExpert.java
and BeerSelect\src\com\example\web\BeerSelect.java

My compilation command for the first program is:
javac -d classes src/com/example/model/BeerExpert.java

This compiles fine and creates a class file in the appropriate subdirectory under classes (classes/com/example/model)

But I get the following error when trying to compile the BeerSelect.java file.

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

I think I'm making a very silly mistake here. But cannot figure out what.
Using Java version 1.5.0_06. The source code is as follows (from the book)

package com.example.model;

import java.util.*;

public class BeerExpert{
public ArrayList<String> getBrands(String color){
ArrayList<String> brands = new ArrayList<String>();
if (color.equals("amber")){
brands.add("Jack Amber");
brands.add("Red Moose");
}
else {
brands.add("JAil PAle Ale");
brands.add("Gout Stout");
}
return (brands);
}
}

package com.example.web;

import com.example.model.BeerExpert;
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{
String c = request.getParameter("color");
BeerExpert be = new BeerExpert();
List result = be.getBrands(c);
request.setAttribute("styles", result);
RequestDispatcher view = request.getRequestDispatcher("result.jsp");
view.forward(request, response);
}
}


Any help is greatly appreciated.

-Jane


Jane
SCJP, SCMAD
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39548
    
  27
This gets asked frequently. Have a look at the various previous discussions.

Also, please UseCodeTags when posting code of any length. It makes it much easier to read.
[ March 06, 2008: Message edited by: Ulf Dittmer ]

Ping & DNS - updated with new look and Ping home screen widget
Jane Joseph
Ranch Hand

Joined: Feb 21, 2008
Posts: 39
Thanks Ulf!

My code compiles fine now

-Jane
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Ch3 Excercise in HFJS
 
Similar Threads
Head First Servlet : Beer Version 2 Problem
weird problem
package does not exist problem
can't import own model
HFSJ- Chap 3