Setting Up a Web Application Project

Download 55.79 Kb.
NameSetting Up a Web Application Project
A typeDocumentation
Setting Up a Web Application Project

  1. Choose File > New Project (Ctrl-Shift-N) from the main menu. Under Categories, select Java Web. Under Projects, select Web Application then click Next.

  2. In Step 2, enter HelloWeb in the Project Name text box.

  3. Specify the Project Location to any directory on your computer. For purposes of this tutorial, this directory is referred to as $PROJECTHOME.

  4. (Optional) Select the Use Dedicated Folder for Storing Libraries checkbox and specify the location for the libraries folder. See Creating Java Projects in Developing Applications with NetBeans IDE for more information on this option.

  5. Click Next. The Server and Settings panel opens. Select the version of Java EE you want to use with your application.

  6. Select the server to which you want to deploy your application. Only servers that are registered with the IDE are listed. Note that the Context Path (i.e., on the server) becomes /HelloWeb, which is based on the name you gave the project in a previous step.

  7. Click Finish.

The IDE creates the $PROJECTHOME/HelloWeb project folder. You can view the project's file structure in the Files window (Ctrl-2), and its logical structure in the Projects window (Ctrl-1).
The project folder contains all of your sources and project metadata, such as the project's Ant build script. The HelloWeb project opens in the IDE. The welcome page,index.jsp, opens in the Source Editor in the main window.

Note. Depending on the server and Java EE version that you specified when you created the project, the IDE might generate index.html as the default welcome page for the web project. You can perform the steps in this tutorial and use the index.html file or you can use the New File wizard to generate an index.jsp file to use as the welcome page, in which case you should delete the index.html file.

Creating and Editing Web Application Source Files

Creating and editing source files is the most important function that the IDE serves. After all, that is probably what you spend most of your day doing. The IDE provides a wide range of tools that can compliment any developer's personal style, whether you prefer to code everything by hand or want the IDE to generate large chunks of code for you.

Creating a Java Package and a Java Source File

  1. In the Projects window, expand the Source Packages node. Note the Source Packages node only contains an empty default package node.

  2. Right-click the Source Packages node and choose New > Java Class. Enter NameHandler in the Class Name text box and type org.mypackage.hello in the Package combo box. Click Finish. Notice that the new file opens in the Source Editor.

  3. In the Source Editor, declare a String variable by typing the following line directly below the class declaration.

String name;

  1. Add the following constructor to the class:

public NameHandler() { }

  1. Add the following line in the NameHandler() constructor:

name = null;

Generating Getter and Setter Methods

  1. Right-click the name field in the Source Editor and choose Refactor > Encapsulate Fields.

The Encapsulate Fields dialog opens, listing the name field. Notice that Fields' Visibility is by default set to private, and Accessors' Visibility to public, indicating that the access modifier for class variable declaration will be specified as private, whereas getter and setter methods will be generated with public and privatemodifiers, respectively.

the encapsulate fields dialog

  1. Click Refactor.

Getter and setter methods are generated for the name field. The modifier for the class variable is set to private while getter and setter methods are generated with public modifiers. The Java class should now look similar to the following.

package org.mypackage.hello;


* @author nbuser

public class NameHandler {
private String name;
/** Creates a new instance of NameHandler */

public NameHandler() {

name = null;

public String getName() {

return name;

public void setName(String name) { = name;


Editing the Default JavaServer Pages File

  1. Refocus the index.jsp file by clicking its tab displayed at the top of the Source Editor.

  2. In the Palette (Ctrl-Shift-8) located to the right of the Source Editor, expand HTML Forms and drag a Form item to a point after the 

     tags in the Source Editor.

The Insert Form dialog box displays.

  1. Specify the following values:

    • Action: response.jsp

    • Method: GET

    • Name: Name Input Form

Click OK. An HTML form is added to the index.jsp file.

input form dialog box

  1. Drag a Text Input item to a point just before the  tag, then specify the following values:

    • Name: name

    • Type: text

Click OK. An HTML  tag is added between the 
 tags. Delete the value attribute from this tag.

  1. Drag a Button item to a point just before the 
  2.  tag. Specify the following values:

    • Label: OK

    • Type: submit

Click OK. An HTML button is added between the 

  1. Type Enter your name: just before the first  tag, then change the default Hello World! text between the 

     tags to Entry Form.

  2. Right-click within the Source Editor and choose Format (Alt-Shift-F) to tidy the format of your code. Your index.jsp file should now appear similar to the following:

  3. JSP Page

  4. Entry Form

  5. Enter your name:

Share in:


Setting Up a Web Application Project iconDevelopment of Android application, Web application and Website for Investickations Project

Setting Up a Web Application Project iconProduct Installation Refer to each product's web site for more information...

Setting Up a Web Application Project iconSetting up cbesw project Environment 1 Cell Box setup

Setting Up a Web Application Project iconTechnology is used to create web application (resides at server side...

Setting Up a Web Application Project iconA web application is an application that is accessed over a network...

Setting Up a Web Application Project iconAbstract As web developers we try to design systems that can protect...

Setting Up a Web Application Project iconEverything went well setting up the transform using the starter example...

Setting Up a Web Application Project iconAbstract This paper explores the effect of using a Web 0 service...

Setting Up a Web Application Project iconGuidelines An accounting manual must be prepared at the outset of...

Setting Up a Web Application Project iconProject Web: Turning Negatives into Positives

forms and shapes

When copying material provide a link © 2017