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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

"Package does not exist" compilation error

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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.
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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.
 
    Bookmark Topic Watch Topic
  • New Topic