这个问题已经在这里有一个答案:
如何在我的Eclipse项目中导入javax.servlet API? 12答案我试图使用eclipse来开发Web应用程序。
我需要使用Tomcat作为我的服务器 。 我已经下载了Tomcat,它正在运行。 但是我的程序没有编译。
我收到以下错误:
导入javax.servlet无法解析。
我需要做什么?
This question already has an answer here:
How do I import the javax.servlet API in my Eclipse project? 14 answersI'm trying to use eclipse for Java EE to develop web applications.
I need to use Tomcat as my server. I've downloaded Tomcat and it's running. But my program doesn't compile.
I get the following error:
The import javax.servlet can't be resolved.
What do I need to do?
最满意答案
您需要将Servlet API添加到类路径中。 在Tomcat 6.0中,这是一个JAR中名为servlet-api.jar的Tomcat的lib文件夹。 您可以将该JAR的引用添加到项目的类路径中,也可以将JAR的副本放在Eclipse项目中,并将其添加到类路径中。
如果要将JAR放在Tomcat的lib文件夹中:
右键单击项目,单击属性 。 选择Java构建路径 。 单击添加外部JAR ... 浏览找到servlet-api.jar并选择它。 单击确定更新构建路径。或者,如果将JAR复制到项目中:
右键单击项目,单击属性 。 选择Java构建路径 。 单击添加JAR ... 在您的项目中查找servlet-api.jar并选择它。 单击确定更新构建路径。You need to add the Servlet API to your classpath. In Tomcat 6.0, this is in a JAR called servlet-api.jar in Tomcat's lib folder. You can either add a reference to that JAR to the project's classpath, or put a copy of the JAR in your Eclipse project and add it to the classpath from there.
If you want to leave the JAR in Tomcat's lib folder:
Right-click the project, click Properties. Choose Java Build Path. Click the Libraries tab Click Add External JARs... Browse to find servlet-api.jar and select it. Click OK to update the build path.Or, if you copy the JAR into your project:
Right-click the project, click Properties. Choose Java Build Path. Click Add JARs... Find servlet-api.jar in your project and select it. Click OK to update the build path.更多推荐
发布评论