Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Ch3 Excercise in HFJS

 
Jane Joseph
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ulf Dittmer
Rancher
Pie
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Jane Joseph
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ulf!

My code compiles fine now

-Jane
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic