您如何使用 Eclipse 开发 Java Servlet?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/206924/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 11:22:29  来源:igfitidea点击:

How do you develop Java Servlets using Eclipse?

javaeclipseservletsplugins

提问by

I would like to program Java servlets using Eclipse and I plan on deploying them using Tomcat. I think I can build the projects using Ant which is bundled with Eclipse. I have the standard Eclipse IDE. What options do I have for doing Servlet development in Eclipse? What changes do I need to make to Eclipse? Do I need to install a plug-in?

我想使用 Eclipse 编写 Java servlet,并计划使用 Tomcat 部署它们。我想我可以使用与 Eclipse 捆绑在一起的 Ant 构建项目。我有标准的 Eclipse IDE。在 Eclipse 中进行 Servlet 开发有哪些选择?我需要对 Eclipse 进行哪些更改?我需要安装插件吗?

回答by LizB

I use Eclipse Java EE edition

我使用 Eclipse Java EE 版

Create a "Dynamic Web Project"

创建一个“动态 Web 项目”

Install a local server in the server view, for the version of Tomcat I'm using. Then debug, and run on that server for testing.

在服务器视图中安装本地服务器,适用于我使用的 Tomcat 版本。然后调试,并在该服务器上运行以进行测试。

When I deploy I export the project to a war file.

当我部署时,我将项目导出到一个 war 文件。

回答by William

You need to install a plugin, There is a free one from the eclipse foundation called the Web Tools Platform. It has all the development functionality that you'll need.

您需要安装一个插件,eclipse 基金会有一个免费的插件,称为Web Tools Platform。它具有您需要的所有开发功能。

You can get the Java EE Edition ofeclipse with has it pre-installed.

您可以获得Eclipse的Java EE 版,并预先安装它。

To create and run your first servlet:

要创建并运行您的第一个 servlet:

  1. New... Project... Dynamic Web Project.
  2. Right click the project... New Servlet.
  3. Write some code in the doGet()method.
  4. Find the servers view in the Java EE perspective, it's usually one of the tabs at the bottom.
  5. Right click in there and select new Server.
  6. Select Tomcat X.X and a wizard will point you to finding the installation.
  7. Right click the server you just created and select Add and Remove...and add your created web project.
  8. Right click your servlet and select Run > Run on Server...
  1. 新建...项目...动态 Web 项目。
  2. 右键单击项目...新建 Servlet。
  3. doGet()方法中编写一些代码。
  4. 在 Java EE 透视图中找到服务器视图,它通常是底部的选项卡之一。
  5. 右键单击那里并选择新服务器。
  6. 选择 Tomcat XX,向导将指向您查找安装。
  7. 右键单击您刚刚创建的服务器并选择添加和删​​除...并添加您创建的 Web 项目。
  8. 右键单击您的 servlet 并选择运行 > 在服务器上运行...

That should do it for you. You can use ant to build here if that's what you'd like but eclipse will actually do the build and automatically deploy the changes to the server. With Tomcat you might have to restart it every now and again depending on the change.

那应该为你做。如果您愿意,您可以使用 ant 在这里构建,但 eclipse 将实际执行构建并自动将更改部署到服务器。使用 Tomcat,您可能需要不时地重新启动它,具体取决于更改。

回答by Martin Dürrmeier

Alternatively you can use Jetty which is (now) part of the Eclipe Platform (the Help system is running Jetty). Besides Jetty is used by Android, Windows Mobile..

或者,您可以使用 Jetty,它(现在)是 Eclipe 平台的一部分(帮助系统正在运行 Jetty)。除了 Jetty 被 Android 使用,Windows Mobile..

To get started check the Eclipse Wikior if you prefer a VideoAnd check out this related Post!

要开始查看Eclipse Wiki或者如果您更喜欢视频并查看此相关帖子