导入javax.servlet无法解析[duplicate](The import javax.servlet can't be resolved [duplicate])

编程入门 行业动态 更新时间:2024-10-25 03:28:58
导入javax.servlet无法解析[duplicate](The import javax.servlet can't be resolved [duplicate])

这个问题已经在这里有一个答案:

如何在我的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 answers

I'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.

更多推荐

本文发布于:2023-07-15 18:56:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1117507.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:servlet   javax   duplicate   resolved   import

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!