• 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

servlet compiling errors  RSS feed

Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am following an exercise from HFJS and encounter compile errors.

I have two servlet files named BeerSelect.java and BeerExpert.java

I create a development like this:
--------------------------model (BeerExpert.java)
--------------------------web (BeerSelect.java)


1) I compiled BeerExpert.java from command prompt:

c:\myprojects\beerv1> javac -classpath "c:\program files\tomcat 5.0\common\lib\servlet-api.jar:classes: ." -d classes src\com\example\model\BeerExpert.java

it created BeerExpert.class successfully in c:\myprojects\beerV1\classes\com\example\model

2) When compiled BeerSelect.java

c:\myprojects\beerv1> javac -classpath "c:\program files\tomcat 5.0\common\lib\servlet-api.jar:classes: ." -d classes src\com\example\web\BeerSelect.java

I got 11 errors.

The error message indicates, such as:
src\com\example\web\BeerSelect.java:3: package com.example.model does not exist"
import com.example.model.*;
src\com\example\web\BeerSelect.java:3: package javax.servlet does not exist"
and so on...




package com.example.web;

import com.example.model.*;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class BeerSelect extends HttpServlet
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
PrintWriter out = response.getWriter();
out.println("Beer Selection Advice <br>");
String c = request.getParameter("color");

/* instantiate the BeerExpert class and call getBrands() */

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 brands = new ArrayList();
if (color.equals("amber")){

brands.add("Jack Amber");
brands.add("Red Moose");


brands.add("Jail Pale Ale");
brands.add("Gout Stout");


Posts: 42974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
On Windows, the character that separates classpath entries is not ":", but ";". So the classpath should read

Also make sure it doesn't contain any extra spaces, like the one that you had after "classes:".
Your buns are mine! But you can have this tiny ad:
global solutions you can do in your home or backyard
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!