leonidn
asked on
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!
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!
you need to make sure that servlet-api.jar is there in the classpath
ASKER
I don't have this file. There are only these ones:
...\eclipse\plugins\org.ec lipse.tomc at_4.1.30. 1\servlet. jar
...\eclipse\plugins\org.ec lipse.help .webapp_3. 1.0\WEB-IN F\lib\serv lets.jar
...\eclipse\plugins\org.ec lipse.tomc at_4.1.30. 1\servlets -common.ja r
...\eclipse\plugins\org.ec lipse.tomc at_4.1.30. 1\servlets -default.j ar
...\eclipse\plugins\org.ec lipse.tomc at_4.1.30. 1\servlets -invoker.j ar
...\eclipse\plugins\org.ec lipse.tomc at_4.1.30. 1\servlets -manager.j ar
...\eclipse\plugins\org.ec
...\eclipse\plugins\org.ec
...\eclipse\plugins\org.ec
...\eclipse\plugins\org.ec
...\eclipse\plugins\org.ec
...\eclipse\plugins\org.ec
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
> ...\eclipse\plugins\org.ec lipse.tomc at_4<wbr/> .1.30.1\se <wbr/>rvle t.jar
Keeping this in the eclipse build path should work.
Keeping this in the eclipse build path should work.
Why dont you try to add external jar (servlets.jar) from Tomcat itself. Any your problem will be solved
Regards,
Meritor
Regards,
Meritor
hi
add external jar form project preferences. If u dont have that try to download it form apache site...
add external jar form project preferences. If u dont have that try to download it form apache site...
ASKER
> 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?
The server I'm going to use is Tomcat, so it sounds like a good idea. Where do I get that jar you mentioned?
you will get that jar file from sun systems. and form apache site also
> 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
<tomcat>/common/lib/serlet
add servlet.jar to your java build path,
right click ur project --> properties --> javaBuildpath --> libraries --> add external jars --> now add servlet.jar
right click ur project --> properties --> javaBuildpath --> libraries --> add external jars --> now add servlet.jar
servlet.jar will be in the folder
<tomcat>/common/lib/servle t.jar
<tomcat>/common/lib/servle
:-)
Is your problem solved or not?
ASKER
Oops... I've just seen two other correct answers (all the same).
I'll ask the CS to reopen the question.
I'll ask the CS to reopen the question.
ASKER
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...
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...
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.
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.