使用 Netbeans IDE 创建第一个 Servlet 应用

原文:https://www.studytonight.com/servlet/creating-servlet-in-netbeans.php

最后一课中,我们创建了第一个 Servlet 应用,但是没有使用任何 IDE。IDE 是 IDE,它使创建应用变得容易得多。我们将学习如何在 NetBeans IDE 和 Eclipse IDE 上创建 Servlet 应用。然后你可以决定你想用哪一个。

使用 IDE 是创建 Servlet 应用最简单的方法。IDE 是一种软件应用,为计算机程序员提供软件开发工具。 EclipsemycpliseNetbeans 都是一些流行 Java IDE 的例子。


在 Netbeans IDE 中创建 Servlet 应用的步骤

要在 Netbeans IDE 中创建 servlet 应用,您需要遵循以下(简单的)步骤:

  1. Open Netbeans IDE, Select File -> New Project

    steps to create servlet application in netbeans


  1. Select Java Web -> Web Application, then click on Next,

    steps to create servlet application in netbeans


  1. Give a name to your project and click on Next,

    steps to create servlet application in netbeans


  1. and then, Click Finish

    steps to create servlet application in netbeans


  1. The complete directory structure required for the Servlet Application will be created automatically by the IDE.

    steps to create servlet application in netbeans


  1. To create a Servlet, open Source Package, right click on default packages -> New -> Servlet.

    steps to create servlet application in netbeans


  1. Give a Name to your Servlet class file,

    steps to create servlet application in netbeans

    steps to create servlet application in netbeans


  1. Now, your Servlet class is ready, and you just need to change the method definitions and you will good to go.

    steps to create servlet application in netbeans


  1. Write some code inside your Servlet class.

    steps to create servlet application in netbeans


  1. Create an HTML file, right click on Web Pages -> New -> HTML

    steps to create servlet application in netbeans


  1. Give it a name. We recommend you to name it index, because browser will always pick up the index.html file automatically from a directory. Index file is read as the first page of the web application.

    steps to create servlet application in netbeans


  1. Write some code inside your HTML file. We have created a hyperlink to our Servlet in our HTML file.

    steps to create servlet application in netbeans


  1. Edit web.xml file. In the web.xml file you can see, we have specified the url-pattern and the servlet-name, this means when hello url is accessed our Servlet file will be executed.

    steps to create servlet application in netbeans


  1. Run your application, right click on your Project and select Run

    steps to create servlet application in netbeans


  1. Click on the link created, to open your Servlet.

    steps to create servlet application in netbeans


  1. Hurray! Our First Servlet class is running.

    steps to create servlet application in netbeans