aspose file tools*
The moose likes Beginning Java and the fly likes servlet compiling errors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "servlet compiling errors" Watch "servlet compiling errors" New topic
Author

servlet compiling errors

chailin fong
Greenhorn

Joined: Oct 15, 2007
Posts: 10
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);

}
}
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42292
    
  64
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:".


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: servlet compiling errors