• 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:
  • 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

cannot compile servlet

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

I am unable to run the servlet version 2 given on page 85(of Head First Servlets and JSP 2nd edition) even after building the directory structures as shown in the book. Specifically, i am unable to compile the servlet called BeerSelect.java. The error shown is "unable to find package com.example.model.*". I have checked and rechecked the directory structures. I am compiling the servlet from MyProjects/beerV1 directory with the command "javac -d classes src/com/example/web/BeerSelect.java" as i have already set the classpath elsewhere. Moreover version 1 of the same servlet is running fine.

Also i would like to report that the deployment descriptor given on page 30 in chapter 1 of the same book does not work well. Tomcat 5.5 shows error in the first line of the web.xml file i.e. "<?xml version=�1.0� encoding=�ISO-8851-1� ?>". Upon removing this line the servlet runs fine.

Please help guys.
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ravi,

1.did you set servlet-api.jar on classpath?

2.which version of tomcat you are using?

Hope This Helps
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by seetharaman venkatasamy:
Hi ravi,

2.which version of tomcat you are using?




sorry, your using tomcat5.5 ...then try this web.xml and put it into the WEB-INF directory


try and let me know
[ August 07, 2008: Message edited by: Ulf Dittmer ]
 
Ravi Gupta
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have copied servlet-api.jar and jsp-api.jar files in the C:\Program Files\Java\jdk1.5\jre\lib\ext directory. This serves the same purpose. Moreover, rest examples are running fine i.e. chapter1,2,3.The problem is with this one only.
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well it seems that you are putting your .java files and .class files in different directories.

so in your case you have to make sure that the package "com.example.model" is in the both directories.
 
Bartender
Posts: 4179
22
IntelliJ IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You said that you are compiling like this:
"javac -d classes src/com/example/web/BeerSelect.java"
So the directory you are in must look like this:
MyProjects/beerV1/src/com/example/web/BeerSelect.java
BeerSelect.java must try to import "com.example.model.*" which is probably found at:
MyProjects/beerV1/src/com/example/model/
The problem is that com.example.model is NOT in your classpath. Your classpath begins in the MyProjects/beerV1/ directory (because that is where you are when you run the javac command) and the package is in the MyProjects/beerV1/src/ directory.

Try running javac from inside the MyProjects/beerV1/src/ directory and compile with:
"javac -d classes com/example/web/BeerSelect.java"

That should fix the problem.
[ August 07, 2008: Message edited by: Steve Luke ]
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Steve Luke,
If you haven't done so already,
please check your private messages.
-DOM
 
reply
    Bookmark Topic Watch Topic
  • New Topic