Eclipse IDE is the most popular Java IDE used in the Industry. It is developed by an open source community and can be downloaded for free from Eclipse.org
Eclipse IDE是业界最流行的Java IDE。 它由开源社区开发,可以从Eclipse.org免费下载。
使用Eclipse IDE创建Servlet的步骤 (Steps to create Servlet using Eclipse IDE)
To create a Servlet application in Eclipse IDE you will need to follow the following steps:
要在Eclipse IDE中创建Servlet应用程序,您将需要执行以下步骤:
Goto File -> New -> Dynamic Web Project
转到文件 -> 新建 -> 动态Web项目
Give a Name to your Project and click Next
为您的项目命名,然后单击下一步
Check Generate web.xml Deployment Descriptor and click Finish
选中“ 生成web.xml部署描述符” ,然后单击“ 完成”。
Now, the complete directory structure of your Project will be automatically created by Eclipse IDE.
现在,您的项目的完整目录结构将由Eclipse IDE自动创建。
Click on First project, go to Java Resources -> src. Right click on src select New -> Servlet
单击第一个项目,转到Java资源 -> src 。 右键单击src选择New- > Servlet
Give Servlet class name and click Next
输入Servlet类名称,然后单击Next。
Give your Servlet class a Nmae of your choice.
为您的Servlet类选择一个Nmae。
Leave everything else to default and click Finish
将其他所有内容保留为默认值,然后单击完成
Now your Servlet is created, write some code inside it. You can take reference from the code in the picture below.
现在,您的Servlet已创建,在其中编写一些代码。 您可以从下图中的代码中获取参考。
Add servlet-api.jar JAR file to your project. Click on Libraries, right click on Web App Libraries select Build Path -> Configure Build Path
将servlet-api.jar JAR文件添加到您的项目中。 单击库 ,右键单击Web App库,选择构建路径 -> 配置构建路径
Click on Add External JARs
单击添加外部JAR
This JAR is now added to your project's build path.
现在,此JAR已添加到项目的构建路径中。
Select servlet-api.jar from Apache Tomcat Directory
从Apache Tomcat目录中选择servlet-api.jar
Now all you have to do is Start the server and run the application.
现在,您要做的就是启动服务器并运行应用程序。
翻译自: https://www.studytonight.com/servlet/creating-servlet-in-eclipse.php