The Student Room Group

The import javax.servlet cannot be resolved

Getting error The import javax.servlet cannot be resolved when using eclipse:

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


The above is auto-generated on creating a new servlet. I cannot find the j2ee.jar file anywhere on my system - could this be the problem? If so, how do I resolve that?

Installed JRE: jre1.6.0_05
Installed Runtime: apache-tomcat-6.0.16
Reply 1
Are you doing this in a Web Project in Eclipse?

I think you need some sort of plugin like: http://www.eclipse.org/webtools/ to be able to make a web project. I don't use Eclispe so I don't if that comes as default when I used to use eclipse for J2EE projects we used this plugin (http://www.myeclipseide.com/), but you have to pay for it.

If you end up still needing to get j2ee.jar manually you just need to get JEE5 installed: http://java.sun.com/javaee/technologies/javaee5.jsp.
Reply 2
Yes Baron is right, you are missing a .jar file that needs to be added to your project - I just love the fact that you have to install the whole Sun Java System Application Server Platform just to get the j2ee.jar :smile:

You may need this: Project > Properties > Java Build Path > Libraries > Add External JARs
Reply 3
Yeh, that's one of the reasons I tend use the Sun App Server, because it is part of the J2EE SDK. Plus it is also good :biggrin:

Tomcat has always been good on developer machines because it has small memory footprint and fast start up time, but now the Sun App Server is based on glassfish, it seems to have those advantages (in the default 'developer' mode), plus it is good to use on a live production server (where Tomcat tends not to be used).

Anyway, I advise not adding any of the jars in the JEE SDK to you project manually. I suggest instead you either get one of the plugins I posted (my housemate says that some people where he works use myeclipse and others use the eclipse webtools, so I guess both are good).

Alternatively just get netbeans (I use this at work). No plugins or seperate JEE SDK/application server required). It comes with tomcat, glassfish and JEE all bundled. Just make sure you get the Web and Java EE package from this page. http://download.netbeans.org/netbeans/6.0/final/

Either way, this will save you having to faff about with all the JEE libraries and will let you create a web project and deploy it to whichever server out of the box.
Reply 4
Baron
Yeh, that's one of the reasons I tend use the Sun App Server, because it is part of the J2EE SDK. Plus it is also good :biggrin:


lol really! :p:

Baron
Alternatively just get netbeans (I use this at work). No plugins or seperate JEE SDK/application server required). It comes with tomcat, glassfish and JEE all bundled. Just make sure you get the Web and Java EE package from this page. http://download.netbeans.org/netbeans/6.0/final/


Thats a good idea, I hope you have the capacity for it though since when i started learning Java and my university recommended netbeans, it made a dent in my hard drive! :rolleyes:
Reply 5
Yeah, we use netbeans for other things, but this part of the project has to be done in Eclipse. Still having no joy with the original problem. Hate Eclipse!!! lol
Reply 6
SillyFencer
Still having no joy with the original problem. Hate Eclipse!!! lol


You installed the J2EE as Baron suggested [plugins]? You get the same error?

Can you show us some code to test? If it's too sensitive then only give relevant snippets. :smile:
Reply 7
abshirf2
You installed the J2EE as Baron suggested [plugins]? You get the same error?

Can you show us some code to test? If it's too sensitive then only give relevant snippets. :smile:

Yup, did that. And all the code is auto-generated on creating a new servlet in Eclipse.
Reply 8
Which of the eclipse plugins did you use?
Reply 9
Baron
Which of the eclipse plugins did you use?

webtools.
Reply 10
I've not used it before so can't really help.

If you haven't seen them yet, there are articles and presentations on how to use web tools here:

http://www.eclipse.org/webtools/community/communityresources.php#articles

Maybe they will help. This looks quite thorough: http://www.windofkeltia.com/j2ee/wtp-tutorial.html
Reply 11
Can you try it again but this time just add the j2ee.jar to you eclipse project as an external jar. I know Baron advised against it, but its worth a try, plus i am use to bodge jobs. :smile:

Latest

Trending

Trending