Solved

The import javax.servlet cannot be resolved

Posted on 2006-07-09
18
16,480 Views
Last Modified: 2013-11-24
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
Comment
Question by:leonidn
  • 4
  • 2
  • 2
  • +5
18 Comments
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 17067619
you need to make sure that servlet-api.jar is there in the classpath
0
 

Author Comment

by:leonidn
ID: 17067751
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
 
LVL 8

Expert Comment

by:kaliyugkaarjun
ID: 17067762
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 86

Accepted Solution

by:
CEHJ earned 50 total points
ID: 17067792
>>
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
 
LVL 23

Expert Comment

by:Ajay-Singh
ID: 17067805
> ...\eclipse\plugins\org.eclipse.tomcat_4<wbr/>.1.30.1\se<wbr/>rvlet.jar
Keeping this in the eclipse build path should work.
0
 
LVL 4

Expert Comment

by:Meritor
ID: 17068586
Why dont you try to add external jar (servlets.jar) from Tomcat itself. Any your problem will be solved

Regards,
Meritor
0
 
LVL 3

Expert Comment

by:anumalas
ID: 17068705
hi

add external jar form project preferences. If u dont have that try to download it form apache site...
 
0
 

Author Comment

by:leonidn
ID: 17068770
> 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
 
LVL 3

Expert Comment

by:anumalas
ID: 17069079
you will get that jar file from sun systems. and form apache site also
0
 
LVL 92

Expert Comment

by:objects
ID: 17069786
> 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
 
LVL 10

Expert Comment

by:mukundha_expert
ID: 17070631
add servlet.jar to your java build path,

right click ur project --> properties --> javaBuildpath --> libraries --> add external jars --> now add servlet.jar
0
 
LVL 10

Expert Comment

by:mukundha_expert
ID: 17070637
servlet.jar will be in the folder
<tomcat>/common/lib/servlet.jar
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17071527
:-)
0
 
LVL 4

Expert Comment

by:Meritor
ID: 17073313
Is your problem solved or not?
0
 

Author Comment

by:leonidn
ID: 17074136
Oops... I've just seen two other correct answers (all the same).
I'll ask the CS to reopen the question.
0
 

Author Comment

by:leonidn
ID: 17074467
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
 
LVL 92

Expert Comment

by:objects
ID: 17077816
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

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Java exception bubble up 2 21
ejb wildfly example 2 22
How to configure empty element in XML Document parser? 15 36
Crystal Reports Licensing Questions 4 34
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question