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

查看:1185
本文介绍了导入javax.servlet无法解析的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 eclipse Java EE 来开发Web应用程序。

I'm trying to use eclipse for Java EE to develop web applications.

我需要使用 Tomcat 作为我的服务器。我已经下载了Tomcat,它正在运行。但是我的程序没有编译。

I need to use Tomcat as my server. I've downloaded Tomcat and it's running. But my program doesn't compile.

我收到以下错误:


导入javax.servlet可以'

The import javax.servlet can't be resolved.

我需要做什么?

推荐答案

您需要将Servlet API添加到您的类路径中。在Tomcat 6.0中,这是在Tomcat的 lib 文件夹中的一个名为 servlet-api.jar 的JAR。您可以将该JAR的引用添加到项目的类路径中,也可以将JAR的副本放在Eclipse项目中,并将其添加到该路径中。

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.

如果你想将JAR放在Tomcat的 lib 文件夹中:

If you want to leave the JAR in Tomcat's lib folder:


  • 右键单击项目,点击属性

  • 选择 Java构建路径

  • 点击添加外部JAR ...

  • 浏览找到 servlet-api.jar 并选择它。

  • 单击确定更新构建路径。

  • Right-click the project, click Properties.
  • Choose Java Build Path.
  • Click Add External JARs...
  • Browse to find servlet-api.jar and select it.
  • Click OK to update the build path.

或者,如果您复制JAR进入您的项目:

Or, if you copy the JAR into your project:


  • 右键单击项目,单击属性

  • 选择 Java Build Path

  • 点击添加JAR ...

  • <在项目中查找 servlet-api.jar ,然后选择。
  • 点击确定更新构建路径/ li>
  • 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.

这篇关于导入javax.servlet无法解析的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆