How to Create an Ajax Autocomplete Text Field / Page 3 | WebReference

How to Create an Ajax Autocomplete Text Field / Page 3


[prev]

How to Create an Ajax Autocomplete Text Field [con't]

Developing the Web Application

Create a New Dynamic Web Project

New Project dialog
New Project dialog

Eclipse supports two types of Web Projects: Static Web Projects and Dynamic Web Projects. We're interested in creating a Dynamic Web Project because it will include some Java components. To create the project, select File->New->Other from the main menu. Then expand the "Web" branch from the list of different project types. Select "Dynamic Web Project" and click the "Next" button to start the wizard:

Here's where we select our target server that we added earlier to the server list. A target server provides the container which will be used to execute our Web application. Moreover, it will provide a set of libraries (jars), added to the project classpath, which are needed to compile Web-related classes. For instance, to create a new Servlet, we need javax.servlet.* packages in order to compile it, since it's not a part of the JDK libraries. Had you not defined a server runtime via the Preferences dialog, you could still define one by clicking on the "New..." button. You can also select an existing project by using the "Browse..." button. Make sure that "Add module to an EAR project" isn't selected. EAR stands for "Enterprise ARchive" file, which is a file format used by Java EE for packaging one or more modules into a single archive. By default, the context root will be the same as the project name. This is used when you access the Web application with a URL, i.e. https://localhost:8080/Autocomplete. Click the "Finish" button to close the dialog and create the Autocomplete project or have a look at the next screens by clicking "Next" button:

New dynamic Web project dialog
New dynamic Web project dialog

Eclipse will create a "Java EE" perspective by default. A perspective is an IDE layout associated to a particular type of development project. The perspectives are selected in the upper right-hand corner above the "Outline" tab. You can compare the Java EE perspective to the "Java" one by clicking on the Java button, immediately to the right of the Java EE one. You'll notice that some of the tabs on left-hand and bottom tabs will change. For instance, the Server tab will disappear and a Javadoc one will appear that wasn't visible in the Java EE perspective.

Eclipse IDE with Web project
Eclipse IDE with Web project

In the Project Explorer pane on the right, you'll see your newly created "Autocomplete" Java Web Project. Under the project are the following folders:

  • JavaSource: src - You will add your custom Java packages and classes to the src folder.
  • build - This is where your compiled Java classes will go.
  • Web Content - A resource folder which mimics the standard WAR structure from the J2EE specification. It will contain the Web resources that will be packaged with your dynamic Web application.
  • Servers - Contains configuration files for your defined servers.

In the next installment we'll be building the Java classes that will handle the AJAX calls from the Autocomplete control. Until then, here's some further reading to get you thinking in Java!

References

Original: March 26, 2008 Digg This Add to del.icio.us


[prev]