Forums Register Login

Ch3 Excercise in HFJS

+Pie Number of slices to send: Send
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
+Pie Number of slices to send: Send
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 ]
+Pie Number of slices to send: Send
Thanks Ulf!

My code compiles fine now

-Jane
Won't you be my neighbor? - Fred Rogers. tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1188 times.
Similar Threads
package does not exist problem
Head First Servlet : Beer Version 2 Problem
weird problem
HFSJ- Chap 3
can't import own model
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 04:08:04.