Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

error: package javax.servlet.http does not exist

I am trying to create my first servlet and I am getting the error above when I try to compile my code. I have read on stackoverflow that this is due to SE JDK not containing the servlet api. However, I am compiling from the command line with the following:

javac -classpath C:/Tomcat7/lib/servlet-api.jar; 
      -d ../classes com/example/web/BeerSelect.java.

As you can see I am making reference to the servlet-api on the command line. Please can you advise why I am still getting this error. I am using tomcat 7

thanks


Solution

For anyone that is interested..I located my problem. It was problem with the Windows command shell and the fact that I had spaces in the directory names. I had the tomcat app saved as "tomcat 7" with a space. I was trying to reach it with "tomcat7" - that is no spaces.. The following line works

javac -classpath .;C:/Tomcat7/lib/servlet-api.jar;
      -d ../classes com/example/web/BeerSelect.java
like image 659
M_x_r Avatar asked Dec 31 '25 19:12

M_x_r


1 Answers

If you are using Maven, you should add the servlet-api 2.5 dependency with the provided scope (see here for more details).

like image 128
Jérôme Verstrynge Avatar answered Jan 03 '26 07:01

Jérôme Verstrynge



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!