C H A P T E R  4

Tutorial--Section 1.1
Application Infrastructure

This chapter describes how to create the Sun Javatrademark Studio Web Application Framework (also known as Application Framework, App Framework, SJSAF, and JATO) application infrastructure needed for all subsequent tasks.


Task 1: New Sun Java Studio Web Application

Before developing any pages, you need to create the Web Application Framework application infrastructure (the WAR directory structure and supporting files). This is a onetime requirement for each Web Application Framework application.

Create an Application Wizard

Before you create the application, you need to decide where the application should be located. Typically, developers develop the application directly in the webapps directory of a servlet container so the application can be tested without deploying it to the target runtime environment. Since you are already using the Sun Java Studio (Studio), you can locate the application anywhere and use the built-in Sun Java System Application Server 7 Standard Edition, Update 1 module to test it in place.

1. Select the Sun Java Studio Enterprise 6 menu option File -> New.

The Choose Template panel displays.

This figure shows the Choose Template panel of the New Wizard, with the Web Application Framework node expanded and Application selected.  

2. Expand the Web Application Framework folder.

3. Select Application.

4. Click Next.

The Application Location panel displays.

This figure shows the Application Location panel of the New Application Wizard.  

The default base directory is your Sun Java Studio user-dir, which might be different than the one shown in this example. You can choose any existing directory to be your base directory for your Web Application Framework applications.



Note - Many developers use the webapps directory of the servlet container in which the application is deployed.

Later in this tutorial, you will see how to run your Web Application Framework application using the Sun Java Studio, so you can put your Web application anywhere you want.



5. Enter JatoTutorial in the Web Context Name field.

The New App Directory field is populated after you make entries in the Base Directory and Context Name fields.

6. Click Next.

The Application Properties panel displays.

This figure shows the Application Properties panel of the New Application Wizard.  

The fields on this panel are populated using the value of the Web Context Name field from the previous panel.

For this tutorial, accept the default values.

7. Click Next.

The Module Properties panel displays.

This figure shows the Module Properties panel of the New Application Wizard.  

For this tutorial, accept the default values.

8. Click Finish.

9. Click OK.

The application is created.



Note - The processing time depends upon your machine.



The new application displays in the Web Application Framework Apps tree in the IDE's Explorer window, which is labeled Web Application Framework Apps.

10. Expand the Application Classes node in the Web Application Framework Apps Explorer tab to see the application layout and observe the code in the two servlet classes that were created.

The left side of this figure shows the application layout along with the property sheet for the MainModuleServlet.java node. The right side of this figure shows the code in the two servlet classes that were created. 

Application Servlet

The application servlet, JatoTutorialAppServletBase, has no special meaning to the application except that it is meant to be a super class for all module servlets in the application.

The Web Application Framework module servlets have events that can be implemented to customize and control the session and request life cycle.

For example:

It is common that all module servlets within the same application require the same behavior for all of these events. Therefore, it is a good idea to implement such behavior for these events in a class that all module servlets can extend.

However, technically speaking, the application servlet is not required. You can customize the hierarchy of the module servlet as long as that hierarchy derives from the Web Application Framework's com.iplanet.jato.ApplicationServletBase file.

This application has only one module, and by definition, one module servlet. So the role of the application servlet is not as beneficial as it would be in multi-module applications.

Module Servlet

The module servlet, MainModuleServlet, is the actual servlet that is invoked for every request. All access to the application goes through this front controller servlet before control is handed to the appropriate request handler class (implemented later in this tutorial).

Not much code is required in this class. All of the necessary request handling code is located in the Web Application Framework's com.iplanet.jato.ApplicationServletBase file. Advanced developers can gain some insight on how requests are handled by reviewing the source code in the com.iplanet.jato.ApplicationServletBase class.

Advanced Tip - Modules

Notice that if the main module folder is selected, its properties are reflected in the property sheet at the bottom of the Studio Explorer window. Notice that its Module property is True. By changing it to False, this module becomes an ordinary folder/package, and the entries in the web.xml file (a standard Web application configuration file) for the MainModuleServlet are removed.

You can make any ordinary folder a Web Application Framework module by right-clicking the folder and selecting the Convert to Module action. You are then prompted to select a Java servlet class from that folder to be the module servlet, or you can provide a name to create a new one.