This week's book giveaway is in the HTML Pages with CSS and JavaScript forum.
We're giving away four copies of Testing JavaScript Applications and have Lucas da Costa on-line!
See this thread for details.
Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

servlet compiling errors

 
Greenhorn
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:
c:\MyProjects\beerV1
--------------------classes
---------------------------com
---------------------------example
---------------------------model
--------------------web
--------------------src
-----------------------com
--------------------------example
--------------------------model (BeerExpert.java)
--------------------------web (BeerSelect.java)


c:\Myprojects\beerV1\src\com\example\web\BeerSelect.java
c:\Myprojects\beerV1\src\com\example\model\BeerExpert.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...


Thanks.


==================================================

//BeerSelect.java

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
{
response.setContentType("text/html");
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());
}

}
}



==============================================


//BeerExpert.java

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");

}
else{

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

return(brands);

}
}
 
Rancher
Posts: 43016
76
  • 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:".
 
Do the next thing next. That’s a pretty good rule. Read the tiny ad, that’s a pretty good rule, too.
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
    Bookmark Topic Watch Topic
  • New Topic