Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

ERROR: package javax.servlet does not exist

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi

i m new to servlets jsp
i worked only on core java.for that i installed jdk.
now i installed apache tomcat4.1.
i wrote a servlet and wen compiling it gives error that

package javax.servlet does not exist.
package javax.servlet.http does not exist.
cannot find symbol class HttpServlet,etc...


In environmetn variables, i set PATH,CLASSPATH,JAVA_HOME,CATALINA_HOME.
wat shud i do to make servlets work?

pls friends clarify my doubt.
 
Ranch Hand
Posts: 146
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Welcome to world of J2EE.

Could you please tell what values have you set for the environment variables? If you are getting the package not found error, this means that your servlet is unable to find the servlet-api.jar/servlet.jar file and hence the classes inside this JAR. Please check the classpaths.

Also, are you using any IDE? If not please do. I suggest Dr.Java or JCreator. You can add the JAR in the classpath very easily using any IDE.

And u are working on Windows or Linux?

Abhishek.
 
vishvar hariraman
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi

I m working on windows.
In CLASSPATH i set to servlet.jar, not to servlet-api.jar.
I m using JCreator only.
How to set calsspath frm JCreator?
Whatever u told, i had done already, i suppose.
Wat wil be the problem?
 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It seems that the compiler (javac) is not able to locate the servlet.jar. There might be several reasons for that. One possible reason could be that you are overriding the CLASSPATH environment variable before running the compiler.
I would suggest do "echo %CLASSPATH%", just before executing javac. This will show you the current value of classpath. I can't think of any reason why it shouldn't work if you see servlet.jar in classpath.

However, you can try passing classpath while compiling -
javac -classpath <path> <source file>

Hope this helps
 
vishvar hariraman
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi

if i compile the files using command prompt it gets compiled,but using JCreator it shows the above errors.
Do I need to set the path of JCreator directory to CLASSPATH?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If it works from the command line, then you've got your classpath right.
You'll have to read the documentation that comes with your IDE to figure out how it deals with classpaths.

This really isn't a servlet issue anymore so..
Moving to the IDE forum.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also get the same error.
I have J2sdk1.4 installed and Tomcat 5.0
when i try compiling the servlet using command line then it shows javax.servlet does not exist.

I searched through my J2sdk bi,library and other folders there is javax.servlet package. Am I using the correct version of java?

I m new to J2ee.

Please help me friends.

I do not use any IDEs .and I work in Windows.
 
Nalini Rajan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in continuation with my last post there is NO javax.servlet package anywhere inside my bin or lib folders under j2sdk.

Please help
 
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The servlet API doesn't come with the JDK -- it comes with Tomcat. Find the file "servlet.jar" or "servlet-api.jar" (the name and location has varied slightly over time) and include that file when you compile your servlets.

I don't recommend using the CLASSPATH environment variable, ever. Instead use the "-classpath" switch to javac. If this is too much typing -- and of course, it is -- then write a batch file or learn to use something like Ant.
reply
    Bookmark Topic Watch Topic
  • New Topic