Hi, I am trying to compile the first example from chapter one of the Head First Servlet & Jsp book. It tells me it can't find the package javax.servlet. I seem to always get lost when trying to figure out the classpaths, so I am assuming that is the problem. This is the command I am entering:
Yes, I have the import in the source file. That is the line the compiler is producing the error. I have the classpath to the jar ok. Maybe it isn't a classpath error at all. If i try to compile it from the directory it resides in, without trying to put it in a jar, it still gives the error. I have compiled other programs before, but never imported this package. Is it possible the package is missing from my installation? If so, do I just reinstall J2SE?
My directory structure is C:\Java\project1\src with this class in the src folder.
I would appreciate any help. I am pulling my hair out trying to figure this out. I have reinstalled my JDK, installed J2EE, checked the tomcat directory to make sure the servlet-api jar is there and nothing helped.
Carol you are in luck. I just had this problem... and I was able to fix it.
what you got to do is set your CLASSPATH variable to appropriatly. Then you don't have to type the classpath while compiling your example.
In my case I had to set the CLASSPATH as follows: OS: Windows XP start, control panel, system, advanced tab, click on the environment variable. On the upper list box (user variables, don't touch the system variables), click New button, then add CLASSPATH on the Variable Name field and I typed E:\Program Files\Apache Software Foundation\Tomcat5.5\common\lib\servlet-api.Jar on the variable value field. You can simply copy the path from explorer and add servlet-api.Jar in the end.
Then compile your code using the following command:
javac -d classes src\Ch1Servlet.java
Let me know if you have any other problem. I encountered some weird problem because of the error on my web.xml file.
I have this same problem! And yes...I can get the servlet to compile by adding setting the CLASSPATH environment variable in Windows....but I should still be able to compile this by using the -classpath option, right? Does anyone know what I'm doing wrong? Here is my source: