Win a copy of Head First Android this week in the Android 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

need help when compile the code

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
//BeerSelect.java

package foo;

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{

java.util.Date today = new java.util.Date();

String c=request.getParameter("color");

BeerExpert be = new BeerExpert();
List result= be.getBrands(c);

response.setContentType("text/html");

PrintWriter out = response.getWriter();

out.println("beer selection advice");

Iterator it=result.iterator();

while(it.hasNext()) {
out.println("<br>try"+ it.next());
}
}

}


//BeerExpert.java


package foo;


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("Rose Amber");
}

else{
brands.add("Jail pale Ale");
brands.add("Gout Stout");
}

return brands;


}

}


when I compile the 2 classes "in same directory".
the only mistake is the compiler always tell me can not found BeerExpert,

BeerExpert be = new BeerExpert();

Anyone can help me figure out? Thanks a lot
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How did you compile ? Make sure that the foo package is in the classpath.
 
jess Chiu
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I cd into foo directory, the 2 class all under this directory.

1) I type: javac BeerExpert.java
and found BeerExpert.class in foo directory

2) I type: javac -classpath /tomcat/common/lib/servlet-api.jar BeerSelect.java

and got this error message

BeerExpert be= new BeerExpert();
can not found BeerExpert

Thanks a lot
jess
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you use the -classpath command line argument, you have to specify that foo must be in the classpath :
javac -classpath /tomcat/common/lib/servlet-api.jar;. BeerSelect.java
or in Unix:
javac -classpath /tomcat/common/lib/servlet-api.jar:. BeerSelect.java
 
jess Chiu
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried your command, still the same

How can I specify "foo" in classpath?

Thanks a lot
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, it was not "." but "..":
javac -classpath /tomcat/common/lib/servlet-api.jar;.. BeerSelect.java
 
jess Chiu
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
great!!! thanks

one little dot make so much difference
 
jess Chiu
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import javax.servlet.jsp.tagext.*;
import javax.servlet.jsp.*;


Need help again. I use same command to complie a tag class, But compiler can not find javax.servlet.jsp.tagext.*; and javax.servlet.jsp.*;


Thanks a lot
 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Make sure that the foo package is in the classpath.


You must set . in the CLASSPATH environment variable.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need a different JAR :

javac -classpath /tomcat/common/lib/servlet-api.jar;/tomcat/common/lib/jsp-api.jar;.. BeerSelect.java
 
You showed up just in time for the waffles! And this tiny ad:
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
reply
    Bookmark Topic Watch Topic
  • New Topic