Two Laptop Bag*
The moose likes Servlets and the fly likes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Reply locked New topic
Author

"Package does not exist" compilation error

Sridhar Venkataraman
Ranch Hand

Joined: May 22, 2006
Posts: 76
I am using the book Head First Servlets and JSP to get up and running on J2EE concepts.

I had successfully managed to run the version 1 of the Beer Application after deployment.

Version 2 involves testing and building the model class and modifying the BeerSelect.java servlet to tie it up with the model (pages 82-85 of the Indian subcontinent edition of the book)

I'm following the instructions exactly as given in the book and I'm also using an identical directory structure as recommended in the book for both my development and deployment environment.

I managed to compile and test the model class (BeerExpert) without any problems. I then modified the code in the servlet (BeerSelect) and tried to recompile it using the same command used to create packages (com.example.model and com.example.web). But I get the following error : [SCREENSHOT : Please click "View Picture in Original Size" at the bottom of the page for better quality]

My Development Enivronment is in the directory : C:\MyMVCProjects\BeerV1
I've placed my BeerExpert.java file in this directory : C:\MyMVCProjects\BeerV1\src\com\example\model
After compilation, the class file for BeerExpert.java has been placed in this directory :C:\MyMVCProjects\BeerV1\classes\com\example\model
Version 1 of the BeerSelect.java servlet is placed in this directory : C:\MyMVCProjects\BeerV1\src\com\example\web
After compilation, the class file of version 1 of the BeerSelect.java servlet has been placed in this directory : C:\MyMVCProjects\BeerV1\classes\com\example\web

However, when I make changes to the version 1 servlet code to incorporate the usage of the model (i.e version 2 of the servlet), it doesn't compile. I have checked the code several times, and I can't see any errors with it as it is a carbon copy of what's in the book.

Can anyone please help me out of this? Thanks in advance.
Sridhar Venkataraman
Ranch Hand

Joined: May 22, 2006
Posts: 76
This is the code for version 2 of the servlet (BeerSelect.java), if it helps (it is identical to the code in the book). BeerExpert.java (the model class) compiled successfully as I have mentioned in my earlier post.

package com.example.web;

import com.example.model.*;
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 {

response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("Beer Selection Advice <br>");
String c = request.getParameter("color");
out.println("<br> Got beer color" + c);

BeerExpert be = new BeerExpert();
List result = be.getBrands(c);
Iterator it = result.iterator();
while(it.hasNext()) {
out.print("<br> try : " + it.next());
}
}
}
Sridhar Venkataraman
Ranch Hand

Joined: May 22, 2006
Posts: 76
I've fixed the error myself, after some banging-head-on-table moments. It was something to do with the CLASSPATH again. My bad.

This topic may be closed now.
PoornimaHemant Jerath
Greenhorn

Joined: Jul 13, 2006
Posts: 17
hi shridhar,

i am using the same book and doing the same code, getting the same 3 errors, could u plz help with the solution.
Thanks in advance.

Poornima


-SCJP 1.4 (86%) , SCWCD(88%)<br />Dont tell your god how big your problems are, tell your problems how big your god is.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

In recent days, there have been a large number of "I can't compile servlets" posts that have been moved to the Java in General (beginner) forum where learning how to compile Java classes is discussed.

Rather than add this topic to that list, I'm going to close this and refer you to that forum where you will find previous topics that cover this subject.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: "Package does not exist" compilation error