C H A P T E R 4 |
Tutorial--Section 1.1 Application Infrastructure |
This chapter describes how to create the Sun Java Studio Web Application Framework (also known as Web Application Framework, App Framework, SJSAF, and JATO) application infrastructure needed for all subsequent tasks.
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.
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 module to test it in place.
1. Select the Sun Java Studio Enterprise 7 menu option File -> New Web Application Framework Application.
The Choose Template panel displays.
2. Expand the Web Application Framework folder.
The Application Location panel displays.
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.
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.
The Application Properties panel displays.
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.
The Module Properties panel displays.
For this tutorial, accept the default values.
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.
11. The Properties Window may not be located where you like it. In order to move windows around in the new IDE, select the window title bar (click and hold down left mouse button) and drag to the location you would like.
While you are dragging the IDE will display a red outline of the new window location demonstrating where and how it will look. Windows can be docked to quadrants of the screen or docked as tabbed panels with other windows. The figure below shows the Properties window placed at the lower left under the Explorer view.
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.
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.
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.
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.
Copyright © 2004, Sun Microsystems, Inc. All Rights Reserved.