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

查看:47
本文介绍了导入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 the Libraries tab
  • 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 构建路径.
  • 点击添加 JAR...
  • 在您的项目中找到 servlet-api.jar 并选择它.
  • 点击确定更新构建路径.
  • 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天全站免登陆