Web Applications II
Peter Komisar © Conestoga College  version 1.0  Fall / 2007

Reference:  Third Draft Document for Review, Sept. 17,2007,
SG24-7501-00 'Rational Application Developer V7 Programming
Guide'.


This is a synopsis of information found in the latter part of
the 12th chapter, 'Developing Web Applications with Servlets
and JSPs'  found in the third draft Document for Review, dated
October 23, SG24-7501-00 Rational Application Developer V7
Programming Guide. It has been prepared for private academic
purposes and is not an effort to publish the contained material.

Any anonymous quotes are from the above noted reference. 

We continue our tour of the Web Application, now
looking at the use of RAD 7 tools to the creation of
Web components.

Don't lose site of the Forest for the Trees

Notice that in this note the 'clicking' reaches a
crescendo. Keep your eye on the headings and
comments as they appear, so we don't lose site
of the bigger tasks that are being accomplished.

Three web components are being generated here,
HTML pages, Java Server Pages and Servlets.
A lot of the procedural 'noise' pertains to dressing
up the views, supplied by the HTML and JSP pages.

Don't Throw the Baby Out With the Bath Water

At the heart of the note, which is burdened with a
lot of GUI procedures, are several excellent servlet
examples that deserve attention in their own right.

The Details of GUI Procedures will not be on the
exam.


Web site Navigation and Appearance

This section instructs on how site pages are defined.
As well the Web Site Designer is used to set up
navigation. Page templates and style sheets are
used to give a uniform look.

The page template is used to block a standard page
with header, navigation menu, footer while the style
sheet defines standard fonts, colors, table formatting,
and other style factors.

Once, the empty pages are created and the application
is run to verify the basic navigation.

Task Descriptions

Create New Page Templates

Page templates provide an efficient way of creating
common Web layouts.  They can be created from an
existing sample page template or be user-defined.
Updates need only be applied once.

Two options
Design-time page templates, those created in the
build phase,  are applied to the example JSPs. 

Dynamic templates allow page template data to
be updated while the application is running.

First,  creating HTML page templates and JSP
page templates are investigated using existing
sample templates. These are then customized
into user-defined templates.
.
The Redbook recommends creating a page template
prior to creating the pages in the Web Site Designer.
This allows the template to be specified for each page
that is created.


Creating an HTML Page Template

The Content Area is added later when the template is
customized.


Files that Will have Been Created in the Theme Directory


New Page Templates Based on Samples Are Not Editable

If a new page template is created from a sample using the
Page Template wizard, page elements of the new template
are read-only, except for the content area. To make changes
to all aspects of the template, the sample template is renamed
to a new template file name.

Delete the Generated Template & Refactor under a New Name

1) Close and delete the itso_html_template.jtpl file created
by the Page Template wizard.

2) Rename the A-01_gray.htpl page template in the theme
directory to itso_html_template.htpl.

3 ) Select the file and from the context menu, Select Refactor
     --> Rename, and enter the new name and click OK.

4)  When prompted with 'Do you want to have the links to or
from those files fixed accordingly?', click Yes.

The RedBank html template now exists in the
 WebContent/Theme/itso_html_template.htpl file.


Create a JSP page Template


Repeat the above steps for JSPs rather than HTML
creating a new page template itso_jsp_template.jtpl.

// notice jtpl vs htpl

This template is used by the RedBank Web site JSPs.

"The underlying mechanism within Application Developer
for applying a template to a JSP is very different to that
used for an html template. "

Although the two templates have the same headers, footers,
and icons two separate templates are required.

Steps to Build the JSP Template

Ditto re: the Editability
The RedBank html template now exists in the
WebContent/Theme/itso_jsp_template.jtpl file.


Customizing Page Templates


Following are some common customizations, such as
modifying the logo shown on the header, altering the
navigation tabs and adding a content area.


Customizing a Static Page Template


The HTML page template, itso_html_template.htpl is
customized in the following ways.


Customize the Logo and Title


 To modify the logo displayed in itso_static_template.htpl

change the image that is referenced.
The html code which reference the image should
be highlighted in the editor.

Modify the source as follows: // quoted from IBM Redbook

From:


<td width="150"><img border="0" width="150" height="55"
alt="Company's LOGO"
src="/RAD7BankBasicWeb/theme/logo_gray.gif"></td>
<td></td>

To:


<td width="70"><img border="0" width="60" height="50"
alt="Company's LOGO"
src="/RAD7BankBasicWeb/theme/itso_logo.gif"></td>
<td><H1>ITSO <Font color="red">RedBank</Font></H1></td>

Also change the <title> tag to the text RedBank.

Confirm in the Preview Tab that the text and logo
are changed.
 
Customize the Links on the Navigation Bar

A navigation bar is a set of links to other web pages,
displayed as a horizontal or vertical bar on a web page.
When applied consistently, the user easily navigates
the site.

"For the RedBank application, it is desirable to have a
list of the children of the top page shown across the top
and a list of ancestor pages, from the currently page
shown up to the root, shown at the bottom."

Application Developer makes the addition navigation
bars easy. The sample template already includes a
navigation bar to the top and bottom of the Web page.
To customize perform the following:

The rates, insurance, and bank pages will be shown
across the top bar on all pages that  use this template.

Instead of siblings the page shows an ancestor tree
back to the main index.


Inserting a Free Table Layout into the Content Area


The free layout table feature creates tables and cells
automatically so that objects can be freely placed on
the page.

To add one do the following:

Customizing a Style Sheet

Style sheets can be created for a page by selecting the
Default style sheet (CSS File) option or by launching
CSS File creation wizard.

In the RedBank example both the HTML and the JSP
templates reference the gray.css style sheet giving them
a common appearance. The following procedure examples
change colors.

// link text, orange, cc6600 is changed to red, FF0000.
// RRGGBB in Hex FFFFFF


// see diagram in the pdf


Launching the Web Site Designer
Features

Creating the Web site Navigation and Pages

The Web Site Designer is used to construct page
navigation and page skeletons. Skeletons will have
been created which can navigate from page to page
using the tabs below the page header and the ancestor
tabs. The content is added later.

Navigation pages and corresponding HTML or JSP
pages are created for the following pages:


Defining Site Navigation / Creating HTML & JSP Skeletons

Create the Root Static Page

Define the Navigation Root 

// index.html is the navigation root, everything else is a navigation candidate

In the Rebook example, itsohome (index.html) is the navigation
root. All other pages are set to the default, which is a navigation
candidate.

Make itsohome the Root
Add Static Pages as children of itsohome.


Create the Dynamic JSP pages

The JSP Pages
Note the Options Button

"The options button is active. This provides options to
specify the Document Markup properties, to have the
wizard automatically generate servlet stubs methods
and to add extra fields to the web.xml file."

Repeat for Other JSP Pages


Repeat the steps for:
// watch spelling and note case-sensitive

Because the showexception page only appears in
response to a problem, it is not part of the standard
navigation.

To Show ExceptionPage in Navigation
Changing the Titles
See the figure in the pdf showing the HTML and JSP
pages that have been created.  // fig 12-21


Verifying the Site Navigation Page Templates


The empty pages can be tested to verify the templates
look as expected and that the links in the header and
footer navigation bars work as required:

Verifying Links & Templates
A browser pane opens on index page and the tabs
for the other pages can be clicked to confirm they are
working.

Verifying  the JSPs

Type URL directly into the browser:

http://localhost:9080/RAD7BankBasicWeb/listAccounts.jsp

The list accounts page is shown.

"Note that the Ancestor trail at the bottom of the page shows
itsohome and redbank, which is the correct ancestor tree for
this page. The same test can be performed for the other JSPs.
To remove the project from the test server, in the Servers view
right-click WebSphere Application Server v6.1, select Add
Remove Projects, and remove RAD7BankBasicEAR.

Alternatively, expand WebSphere Application Server v6.1,
right-click the RAD7BankBasicEAR project and select
Remove."

Developing Static Web Resources

Content is now created for the four static pages.
In the process features of Page Designer are shown.
Page Designer allows HTML elements from the Pallet
to be drag and dropped onto the page. HTML fragments
can also be imported directly into the source tab. 

Section Topics

Create the index.html Page Content
  // text, links


In the following example how to add static text to the
home index page is described. A link is added to the
page to the IBM Redbooks Web site.


Inserting a Link

// see diagram Figure 12-23.


Creating a Table in the rates.html Page


To add a table containing interest rates
 
Import the Contents of the insurance.html Page


Import the Redbank.html page Contents

Repeat the import of the body of the redbank.html file:


Developing the Dynamic Web Resources

Application Developer also provides several wizards help
you quickly build JavaServer Pages (JSPs) and Java servlets,
even if you are not an expert programmer. These products
can be used as is, or further modified.


What the Wizards Do


The following example servlets are built using the wizards.
The code content is imported from the sample solution.
// JSPs are covered in the next section

Working with Servlets

To review, Servlets are server-side Java components based
on Sun's Java Servlet API. RAD 7 supports the Servlet 2.4 API
capable of generating dynamic responses to web client requests.

The Web Server determines, based on the request URI, which
servlet to forward requests to. The servlet executes it's logic on
the request and builds an HTML response which is returned to
the client or forwarded to a JSP.

From the Workbench
Implemented Servlets
The command or action pattern is applied to implement the
PerformTransaction servlet.

Adding RAD7Java as a Web Library Project

To proceed with servlet class implementation, a reference
must be made from the RAD7BankBasicWeb project to the
RAD7Java project. This is  because servlets call methods
from classes in this project.

 // connects servlet calls to Java model developed in
// Java application section

The facility, Web Library projects  allows a Java project to be
associated with a Web project enabling Java resources in the
Web project to call resources in the Java project.

When the WAR file is built, a JAR file representing the Java
project is automatically added to the WEB-INF/lib directory.

To add RAD7Java as a Web Library project:
// see Figure 12-27

RAD7Java classes can now be accessed by Java code in
RAD7BankBasicWeb.

Implementing the ListAccounts Servlet to the Web Project

RAD provides a servlet wizard to assist  adding servlets to
Web applications.
The wizard automatically generates the URL mapping /ListAccounts
for the new servlet. Different, or additional URL mappings are
required, these can be added though not needed in the example.

For the ListAccounts servlet, only doGet and doPost are selected.

// gets are used with direct links, when no information has to be
// sent to the server. HTTP posts are used to process form data
// There is no initialization required so init( ) method is not selected.

The servlet is generated and added to the project. The source
code is found in the Java Resources folder of the project. The
configuration for the servlet is found in Servlets tab of the Web
deployment descriptor.

"Now open the deployment descriptor for the RAD7BankBasicWeb
(immediately under the project in the Project Explorer), and click
on the Servlets tab. Note that the ListAccounts servlet is listed."

Implementing the ListAccounts servlet  // "fleshing out the skeleton"

A skeleton servlet has been created that doesn't do
anything.

ListAccounts Servlet Code 
// from IBM 7501 sample

// javadoc comments have been stripped out to simplify the view.
// They are useful for understanding the code. See the original
// code at directory location noted above. Other impromptu
// comments have been added

package itso.rad7.webapps.servlet;

import itso.rad7.bank.ifc.Bank;
import itso.rad7.bank.impl.ITSOBank;
import itso.rad7.bank.model.Account;
import itso.rad7.bank.model.Customer;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.Servlet;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class ListAccounts
        extends HttpServlet
        implements Servlet
{
    private static final long serialVersionUID = 1492902037158065146L;

// both doGet( ) and doPost( ) call performTask( )

    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException
    {
        performTask(req, resp);
    }

 
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException
    {
        performTask(req, resp);
    }

  
    private void performTask(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException
    {
        try
        {
            // Get input parameter and keep it on the HTTP session
            String customerNumber = req.getParameter("customerNumber");
            HttpSession session = req.getSession( );
            if (customerNumber == null)
                customerNumber = (String) session.getAttribute("customerNumber");
            else
                session.setAttribute("customerNumber", customerNumber);
           
            // Control logic - Create the new banking facade
            Bank bank = ITSOBank.getBank();

            // Retrieve customer and related accounts
            Customer customer = bank.searchCustomerBySsn(customerNumber);

            ArrayList<Account> accountlist = bank.getAccountsForCustomer(customerNumber);
            Account[] accounts = accountlist.toArray(new Account[accountlist.size()]);

            // Response - Set the request attributes for future rendering
            req.setAttribute("customer", customer);
            req.setAttribute("accounts", accounts);
           
            // Call the presentation renderer
            ServletContext ctx = getServletContext();
            RequestDispatcher disp = ctx.getRequestDispatcher("listAccounts.jsp");
            disp.forward(req, resp);
        }
        catch (Exception e)
        {
            // set up error information and forward to the error page
            req.setAttribute("message", e.getMessage());
            req.setAttribute("forward", "index.html");
            ServletContext ctx = getServletContext();
            RequestDispatcher disp = ctx.getRequestDispatcher("showException.jsp");
            disp.forward(req, resp);
        }
    }
}


In the ListAccounts.java source code the doPost( )  and doGet( ) 
methods are implemented. Both call the performTask( ) method.

The performTask method does the following:
// abbreviation of the Redbook pdf explanation
// See Figure 12-8

ListAccounts servlet is complete. Save changes and close editor.

// the next three servlets are described and then adding them
// follows the detailed procedure
described above



Implementing the UpdateCustomer servlet


The UpdateCustomer servlet updates customer information.
It is invoked from the ListAccounts JSP servlet. The servlet
uses the SSN of the customer which has already been placed
on the session by the ListAccounts servlet).

The title, firstName and lastName parameters are extracted from
the HttpRequest object. After calling getCustomer( ) simple setter
methods on the Customer class are used to update the details.

The procedure for creating ListAccounts servlet and adding it
to the project is followed for UpdateCustomer.

Source Code

c:\7501code\webapps\itso.rad7.webapps.servlet\UpdateCustomer.java

UpdateCustomer Code
// from IBM 7501 sample javadoc comments are removed

package itso.rad7.webapps.servlet;


import itso.rad7.bank.ifc.Bank;
import itso.rad7.bank.impl.ITSOBank;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.Servlet;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;



public class UpdateCustomer
        extends HttpServlet
        implements Servlet
{
    private static final long serialVersionUID = 6859812308406444467L;

   
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException
    {
        performTask(req, resp);
    }

   
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException
    {
        performTask(req, resp);
    }

   
    private void performTask(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException
    {
        try
        {
            // Get input parameters
            String title = req.getParameter("title");
            String firstName = req.getParameter("firstName");
            String lastName = req.getParameter("lastName");
           
            // retrieve the SSN from the session
            HttpSession session = req.getSession();
            String ssn = (String) session.getAttribute("customerNumber");
           
            // Control logic - Create the new banking facade
            Bank bank = ITSOBank.getBank();
           
            // Update customer information
            bank.updateCustomer(ssn, title, firstName, lastName);
                       
            // Call the presentation renderer
            ServletContext ctx = getServletContext();
            RequestDispatcher disp = ctx.getRequestDispatcher("ListAccounts");
            disp.forward(req, resp);
        }
        catch (Exception e)
        {
            // set up error information and forward to the error page
            req.setAttribute("message", e.getMessage());
            req.setAttribute("forward", "index.html");
            ServletContext ctx = getServletContext();
            RequestDispatcher disp = ctx.getRequestDispatcher("showException.jsp");
            disp.forward(req, resp);
        }
    }
}


Implementing the AccountDetails servlet

AccountDetails retrieves the account details and forwards
them to accountDetails.jsp for showing. The servlet expects
the parameter accountId in the request which specifies the
account for which data should be shown. "The servlet then
calls the bank.getAccount(..) method which returns an Account
object and adds it as a variable to the request. It then uses
the RequestDispatcher to forward the request onto the
accountDetails.jsp."

// Follow the procedure as above to add servlet to project

IBM 7501 Source Code for AccountDetails

c:\7501code\webapps\itso.rad7.webapps.servlet\AccountDetails.java

// Note: In a real-life scenarion security and authorization would be applied


Implementing the Logout servlet

The Logout servlet is used for logging the customer out
of the RedBank application. The servlet requires no
parameters. It only action is to remove the SSN from the
session, by calling the session.removeAttribute( ) and
session.invalidate( ) methods. It uses the RequestDispatcher
class to return the browser to the index.html page.

// Follow the procedure as above to add servlet to project

IBM 7501 Source Code for Logout

c:\7501code\webapps\itso.rad7.webapps.servlet\Logout.java


Implementing the PerformTransaction Command Classes

"In the PerformTransaction servlet a command design
pattern is used to implement it as a front controller class
that forwards control to one of the four command objects
namely Deposit, Withdraw, Transfer, and ListTransactions."

// for a reminder see page 484 of the pdf


IBM 7501 Source Code for PerformTransaction


C:\7501code\webapps\itso.rad7.webapps.command

Create a new Package
Importing Java Command Classes
These command classes perform the operations on the
RedBank model classes  through the Bank facade. They
also return the file-name for the next screen to be shown
after the command has been executed.

With the command objects available,  the PerformTransaction
servlet can be created. The servlet determines what command
to execute from the value of the transaction request parameter.

The servlet class should be placed in the package
itso.rad7.webapps.servlet.

// Follow the procedure as above to add servlet to project


IBM 7501 Source Code for
PerformTransaction


c:\7501code\webapps\itso.rad7.webapps.servlet\PerformTransaction.java

package itso.rad7.webapps.servlet;

import itso.rad7.webapps.command.*;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.RequestDispatcher;
import javax.servlet.Servlet;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;



public class PerformTransaction
        extends HttpServlet
        implements Servlet
{
    private static final long serialVersionUID = -6100378212929212231L;
    private Map<String, Command> commands;
   
    public PerformTransaction()
    {
        commands = new HashMap<String, Command>();
       
        commands.put("deposit", new DepositCommand());
        commands.put("withdraw", new WithdrawCommand());
        commands.put("transfer", new TransferCommand());
        commands.put("list", new ListTransactionsCommand());
    }
   
   
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException
    {
        performTask(req, resp);
    }

   
    protected void doPost(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException
    {
        performTask(req, resp);
    }

   
    private void performTask(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException
    {
        String transaction = null;
       
        try
        {
            // Get input parameter and keep it on the HTTP session
            transaction = req.getParameter("transaction");
           
            Command command = (Command)commands.get(transaction);
            if (command != null)
            {
                command.execute(req, resp);
               
                String forwardView = command.getForwardView();
               
                if (forwardView != null)
                {
                    // Call the presentation renderer
                    ServletContext ctx = getServletContext();
                    RequestDispatcher disp = ctx.getRequestDispatcher(forwardView);
                    disp.forward(req, resp);
                }
            }
            else
            {
                // set up error information and forward to the error page
                req.setAttribute("message", "Unknown transaction: "+transaction);
                req.setAttribute("forward", "index.html");
                ServletContext ctx = getServletContext();
                RequestDispatcher disp = ctx.getRequestDispatcher("showException.jsp");
                disp.forward(req, resp);
            }
        }
        catch (Exception e)
        {
            // set up error information and forward to the error page
            req.setAttribute("message", e.getMessage());
            req.setAttribute("forward", "index.html");
            ServletContext ctx = getServletContext();
            RequestDispatcher disp = ctx.getRequestDispatcher("showException.jsp");
            disp.forward(req, resp);
        }
    }
}


PerformTransaction stores a HashMap of the action strings
deposit, withdraw, transfer, and list which map to instances of
the Command classes. Both the doGet and doPost methods
call performTask. In the performTask method the execute
method is called on the appropriate Command class.
After the execute is completed, the getForwardView( ) method
returns the next page to display while the RequestDispatcher
forwards the request to the next page.


Working with JSPs


Just as HTML pages, JSP files are edited in Page Designer.
For JSP pages the Palette view has additional elements:
The IBM pdf describes building listAccounts.jsp in detail
while the other JSPs are imported.

Implementing the List Accounts JSP

Adding static content to a JSP file is done with the Page
Designer tool in the same way as for an HTML file. It is also
possible to add the standard JSP declarations, scriptlets,
expressions, and tags, or any other custom tag developed
or retrieved from the internet.

The listAccounts.jsp file is built up using page data variables
(for customer,accounts and the array of customer Account
classes). The ListAccounts servlet makes these variables
available to the JSP where they are accessed by JSP Java
code and tags.


Completing the listAccounts.jsp file Body

// adding variables
// variables are scoped or 'visible' at different levels,
// application, page, session & request
// adding a Form, uses Post HTTP method
// Add a table with customer information:
// Inserting the customer JavaBean

// Add a row and the Submit button


In the Insert JavaBean wizard (Figure 12-32) do the following:
" The wizard inserts a JSTL c:forEach tag and an HTML
table with headings, as entered in the Insert JavaBean
window. Because we selected Output link as the Control
Type for each column, corresponding c:url tags have been
inserted."

Now the URL for the links need editing, making sure they are
identical and to pass the accountId variable as a URl parameter.

Now a parameter must be added to this URL to ensure
the link goes to the correct account.
This adds a parameter to the account url with a name of
accountId and the value of the accountNumber request
variable.

Repeat for second c:url tag

Repeat the two previous steps to add a parameter
to the second c:url tag in the Balance column,
showing the text Account Number{}. Note the field
values are the same as used in step c, accountId
in the Name field and ${varAccounts.accountNumber}
in the Value field.

Right Justification
In the Source tab the JSP code displays the accounts as
a list, "using the c:forEach tag to loop through each account,
and the c:out tag to reference the current loop variable. The
c:url tag builds a URL to AccountDetails and the c:param tag
adds the accountId parameter (with account number value)
to that URL.

It is easier to look at the JSP code to see what has
been accomplished.

The big picture here is that dynamic HTML page
can be loaded with information provided from the
Java Model that is serving in the back-end of the
application.

IBM Redbook JSP code with JSTL tags to display accounts

<c:forEach var="varAccounts" items="${requestScope.accounts}">
<tr>
<td>
<c:url value="AccountDetails" var="urlVariable">
<c:param name="accountId"
value="${varAccounts.accountNumber}"></c:param>
</c:url>
<a href="<c:out value='${urlVariable}' />">
<c:out value="${varAccounts.accountNumber}"></c:out>
</a>
</td>
<td align="right">
<c:url value="AccountDetails" var="urlVariable">
<c:param name="accountId"
value="${varAccounts.accountNumber}"></c:param>
</c:url>
<a href="<c:out value='${urlVariable}' />">
<c:out value="${varAccounts.balance}" />
</a>
</td>
</tr>
</c:forEach>


Add a Horizontal Rule and a Logout Form

// Make the title, first name and last name entry fields

The remaining part is to change the title, first name and
last name to be entry fields, used to update customer details.

Repeat this for the first name and last name fields:

<td><input type="text" name="firstName"
value="<c:out value='${requestScope.customer.firstName}' />" /></td>
......
<td><input type="text" name="lastName"
value="<c:out value='${requestScope.customer.lastName}' />" /></td>

This changes the customer fields from display only fields
to be editable, so that the details can be changed.

Formatting a Big Decimal

The balance is a BigDecimal and must formatted,
otherwise it displays with many digits:
Implement the other JSPs

The other JSPs have already been created as part of the
model solution. These were build by a similar process of
adding request beans to the JSPs and building html and
JSP elements around them.

Importing other JSP files

Caveat from the IBM RAD 7 PDF

" Unfortunately these pages will not have the associated request beans showing on in the Page Data view. These are maintained in the .jspPeristence file immediately under the Web project directory, but have to be specifically added to the PageData View for Application Developer to be aware of them. For completeness, you can add the required variables to the appropriate Page
Data view. Open the JSP file and in the Page Data view select Scripting Variables → New → Request Scope Variable"



Account Details JSP 
// all the JSPs are covered


The accountDetails.jsp shows details for a particular
customer account and gives options to execute a
transaction:

Key Features

"The JSP uses a single request variable called account
to populate the top portion of the body of the page, which
shows the account number and balance."

The middle section is a simple static form, providing fields
for the details of a transaction. It posts the request to the
PerformTransaction servlet for processing.

The Customer Details button navigates the user to the
listAccounts.jsp page.

// see Figure 12-37.


List Transactions JSP


"The listTransactions.jsp shows a read only view of
the account including the account number and balance
plus a list of all transactions:"

// uses a JavaBean

The JSP uses two request variables, account and transactions.
The first section of the page uses the account request bean to
populate a table showing the account number and balance.

The middle section uses the transactions[ ] request bean to
show a list of transactions. The JSTL tag library is used to iterate
through the transaction  list and build up an HTML representation
of the transaction history.

The Account Details button returns the browser to the
accountDetails.jsp page.

// see Figure 12-38.


Testing the Web Application

Prerequisites to running the sample Web application

c:\7501code\zInterchangeFiles\webapps\RAD7BankBasicWeb.zip

// see “Importing sample code from a project interchange file” on page 1312

Running the Sample Web application

The main page should display in  a Web browser inside
Application Developer.

Verifying the RedBank Web application

Once you have launched the application by running it on
the test server, there are some basic steps that can be
taken to verify the Web application is working properly.

From the main page, select the redbank menu option.
In the RedBank page type a customer social security number,
for example, 444-44-4444. Press submit. Craig Flemings
page should come up. From here, update, log out and
list transactions can be tested.



Assignment


Do one of the following

1 ) Follow the procedures described in the note to generate
each of the pieces of the web application. Submit screen
shots of the Test outputs listed at the end of the chapter.

// If you spend a good amount of time with this but fail
// to get the test outputs, screen shot the results and
// and explain what happened.


OR

2 )Investigating HttpServlets.

a ) Use the Eclipse or RAD 7 to generate a servlet skeleton
that extends HttpServlet. This class implements the Servlet
interface which will list the life cycle methods of servlets.

or
 
b ) You may also build this sample using other documentation
such as the J2EE API documentation.

Stub out all the life cycle methods of Servlet class and include
the important methods of HttpServlet. Using the J2EE
documentation provide in Java comments a line or two as
to what each method is used for. Include a description of the
component parts of the HttpServlet.

If you wish, you can do both questions!