This section describes the concepts and tasks associated with creating the presentation logic for web applications and describes how to use Netscape Application Builder's Java editor and Properties window to customize servlets..
About Java Servlets
Standard Servlets
What the NAS Extended Runtime Servlet Model Provides
Creating and Editing Servlets
Creating FormActionHandlers to Process Requests
Importing Servlets
Working with BaseServlet Files
Working with Session Management
Accessing Data Sources via JDBC
Validation
Additional Programming Considerations
They are an alternative to a CGI script.
They are invoked by a browser/client request.
They communicate using request and a response objects.
They output content via HTML streaming.
They simplify HTTP programming.
They control the application by specifying the flow of control, for example, which enterprise components to activate, what to cache, and which HTML pages or JSP files to invoke.
They are portable.
Servlet configuration, or "NTV" (name-type-value-pair) files.
JDBC RowSet APIs
Session management mechanisms
Enterprise JavaBeans
JavaServer Pages
Netscape Application Server Standard (distributed)
Servlet Standard (nondistributed)
Choose Development options from the Tools menu.
Choose the Code Generation tab.
Uncheck the "Use Extended NAS API for Generic Servlet?" option.
Click OK.
Note. Other Netscape Application Builder wizards that create servlets only use the NAS extended API, which is not standard.
The ability to specify RowSet objects in the servlet configuration (NTV) file which reference query results (.gxq) files and are instantiated by the NAB 4.0 runtime model. All specified RowSet objects are added to the request object when your project's BaseServlet object calls the initRowSets() method. This feature enables the JavaServer Page editor to bind specified data (at design time) to an actual component by identifying which database rows and columns contain the actual query results data without needing an object-relational binding class.
The ability to specify a default template in the servlet configuration file (NTV file). The Netscape Application Builder 4.0 runtime model retrieves the default template, and the generated code can call includeDefaultJSP(), which is generated for you in the project's BaseServlet Java file.
The ability to use Action handlers, which are a server concept. Typically, when handling events, you can create one entry point to deal with all incoming events, which is the defaultAction() method. Or you can create one method per event, where one method is called for one event type; this technique represents the "FormActionHandlers" approach as described in Creating FormActionHandlers to Process Requests.Netscape Application Builder uses the latter approach in the Results Wizard.
The ability to use automated parameter validation, which is discussed in "Validating Data Entered on a Form" on page 347.
The BaseUtil class's initRowSets() method makes explicit calls to initialize row sets that are enumerated and described in the Servlet configuration files (NTV files).
Checks if your servlet supports FormActionHandlersmethods for "multiple entry-point" servlets which need to respond to various types of user actions (as opposed to "single entry-point" servlets which only need to process a single type of response action).
If so, it calls the associated action handlerthe actual method specified in the NTV file for a specific type of action dictated by one of the user actions defined by the multiple entry-point servlet.
If not, the servlet calls defaultAction(), which in its base implementation, validates the inputs.
If successfully handled, the servlet processes the output, most often by calling a JSP page. The default page is stored in the defaultTemplate entry in the NTV file, though this can be changed by calling setDefaultTemplate() anytime after initRowSets() is called.
The servlet then returns the output page to the user.
Creating Servlets via the Add File(s) Dialog Box
Editing Servlets
Handling Servlet Output
Registering, Compiling, and Testing Servlets
Run the appropriate new servlet wizard.
Edit the Netscape Application Builder-generated code.
Compile the servlets.
Test the servlets.
Debug the servlets.
Open the servlet.
Choose the Properties window and click the Events tab.
Choose Add and enter the input-action name and the method to call when the action occurs.
The input-action name must match the submit value, which is the name of the button, in your JSP. The method must be implemented in your servlet. You can either select the method from the pop-up list or type in the method name yourself. If you did not create the method first, you may choose to type in the method name; in which case, Netscape Application Builder creates the method for you.
Copy the servlet file to a directory under the NAS root.
Select Import Servlet(s) from the Project menu.
Select the servlet file, either by navigating or by entering the file name, and click Add.
Produce common error handling.
Produce common presentation elements, such as corporate banners.
Provide debugging helper functions, such as to log the current date and time and the last executed servlet.
Record a history of which pages the user has visited during the session.
Increase security by requiring the user to log in to a secured session before running certain portions of the application.
In an online shopping application, keep track of items in the user's shopping cart.
Using an AppResource Class
Modifying Session Variables
Using an appInfo.ntv File
Click the AppResource.java file.
Select the Session Variables property in the Properties window.
Expand this property to see a list of session variables.
You can rename, delete, or add values to this list.
Session information
Links to all application servlet files
Double-click the appResource.java file to open the editor.
Right-click and choose the Properties menu item (or from the View menu, choose Properties; or select the Outline Tab View and double-click the AppResource line (the only line in the Outline view for appResource.java files), or, again, right-click and choose the Properties menu item.
If the Properties window is already open, clicking in the opened editor displays the properties for the appResource.java file. If no properties are displayed, make sure that the following conditions are true:
The appResource.java file is the application resource file for your application; for further information, see Setting Project Options.
The appResource.java file extends com.netscape.server.servlet.extension.DefaultHttpSession[2]
Using the Inspector, you should see the following editable items:
application name
session flag properties; one for distribution type, and one for persistence
use NAS session flag
session timeout
session variables
The Session Variables property has a plus [+] sign in front of it. Clicking on this shows you the Variable accessors that have been defined on the AppResource file. Session accessors include any method that starts with set and takes a String or starts with get. You can add a new get/set method pair by typing the name of your session variable in the [New Item] sub-property. Once created, the methods can be renamed from the Properties window and deleted by clicking the Delete key.
Highlight Parameter under Validation.
Click the custom editor button.
The following Edit property dialog box appears:
About GX Tags
Calling JavaServer Pages
Using setDefaultTemplate() to Change the Output JSP
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("JSPname.jsp"); dispatcher.forward(request, response);