简体   繁体   中英

Eclipse: Imports not being recognized

I'm using in my Eclipse (Java EE edition) project some classes, like the ServletConfig , for example. If I just add some code with an object of this class without importing it, and click on the error sign (where should appear the import option), it only shows the option to create a class with that name. And if I import it anyway:

import javax.servlet.ServletConfig;

It points an error and shows me the option to create the class 'ServletConfig' in packgae 'javax.servler' . It was working on another computer with Windows 7. The one I'm using is Windows 8.1.

Help!

It sounds as if your project isn't configure as a web project but rather as a plain Java project. Usually, you would do it when you create a project. You'd select File / New / Dynamic Web Project .

If you haven't done so, you should be able the fix the configuration. In the project settings, go to Project Facets and check Dynamic Web Module .

在此处输入图片说明

If I'm not mistaken, you'll need to set up a web server runtime environment as well. First go to Eclipse's preferences and select Server / Runtime Environments . If the list is empty, add one.

在此处输入图片说明

Then go to the project settings again and make sure there is a targeted runtime selected:

在此处输入图片说明

If everything goes ok, the project explorer will show all the web server jars in Java Resources / Libraries / Apache Tomcat v7.0 (or whatever your environment is called). One of the jars is servlet-api.jar and contains the classes you're looking for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM