• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 16597
  • Last Modified:

The import javax.servlet cannot be resolved

Hello,

I tried to compile the following code in Java 5.0 (under Eclipse):

################################################################################

package hall;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HelloWorld extends HttpServlet {
      public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            PrintWriter out = response.getWriter();
            out.println("Hello World");
      }
}

################################################################################

For some reason I get loads of errors, and the first one is "The import javax.servlet cannot be resolved" (I think all the other errors are just cascading errors).

Am I doing something wrong?

Thanks!
0
leonidn
Asked:
leonidn
  • 4
  • 2
  • 2
  • +5
1 Solution
 
Ajay-SinghCommented:
you need to make sure that servlet-api.jar is there in the classpath
0
 
leonidnAuthor Commented:
I don't have this file. There are only these ones:

...\eclipse\plugins\org.eclipse.tomcat_4.1.30.1\servlet.jar
...\eclipse\plugins\org.eclipse.help.webapp_3.1.0\WEB-INF\lib\servlets.jar
...\eclipse\plugins\org.eclipse.tomcat_4.1.30.1\servlets-common.jar
...\eclipse\plugins\org.eclipse.tomcat_4.1.30.1\servlets-default.jar
...\eclipse\plugins\org.eclipse.tomcat_4.1.30.1\servlets-invoker.jar
...\eclipse\plugins\org.eclipse.tomcat_4.1.30.1\servlets-manager.jar
0
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

 
CEHJCommented:
>>
I don't have this file. There are only these ones:

...\eclipse\plugins\org.eclipse.tomcat_4.1.30.1\servlet.jar
>>

If you put that first one on your build path you should be OK
0
 
Ajay-SinghCommented:
> ...\eclipse\plugins\org.eclipse.tomcat_4<wbr/>.1.30.1\se<wbr/>rvlet.jar
Keeping this in the eclipse build path should work.
0
 
MeritorCommented:
Why dont you try to add external jar (servlets.jar) from Tomcat itself. Any your problem will be solved

Regards,
Meritor
0
 
anumalasCommented:
hi

add external jar form project preferences. If u dont have that try to download it form apache site...
 
0
 
leonidnAuthor Commented:
> Why dont you try to add external jar (servlets.jar) from Tomcat itself. Any your problem will be solved

The server I'm going to use is Tomcat, so it sounds like a good idea. Where do I get that jar you mentioned?
0
 
anumalasCommented:
you will get that jar file from sun systems. and form apache site also
0
 
objectsCommented:
> The server I'm going to use is Tomcat, so it sounds like a good idea. Where do I get that jar you mentioned?

<tomcat>/common/lib/serlet-api.jar
0
 
mukundha_expertCommented:
add servlet.jar to your java build path,

right click ur project --> properties --> javaBuildpath --> libraries --> add external jars --> now add servlet.jar
0
 
mukundha_expertCommented:
servlet.jar will be in the folder
<tomcat>/common/lib/servlet.jar
0
 
CEHJCommented:
:-)
0
 
MeritorCommented:
Is your problem solved or not?
0
 
leonidnAuthor Commented:
Oops... I've just seen two other correct answers (all the same).
I'll ask the CS to reopen the question.
0
 
leonidnAuthor Commented:
I accepted the first correct answer given.
There were also 3 correct replies, that were exactly the same.
Since I can't give less than 20 points when splitting, I had no choice but accept the first correct answer.

Please, don't repeat an answer if already written by someone else...
0
 
objectsCommented:
Well the first correct comment was from Ajay-Singh.
And the more correct comment was from Meritor, which you actually agreed with. If you weren't interested in his/her answer then you shouldn't have asked for more information.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

  • 4
  • 2
  • 2
  • +5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now