Вы находитесь на странице: 1из 42

This banking application will enable customers to use

the Web site of a bank to perform banking transactions online.

The banking application will have the following functionalities:

 The application will enable a user to open an account with the bank.
 The application will enable an account holder of the bank to register
to use the application.
 The application will enable registered account holders to log on to the
banking web site after entering their login details.The banking
application will enable the account holders to view their account
details.The registered user also be able to modify any personal details
such as address or phone number.
 The application will also provide utilities such as an interest
calculator and a foreign exchange calculator.
 The application will also display the number of the hits on the
banking web site.
Welcome Page

Home Page

Login Page Registration Page For Registration Page For Interest Calculator
Account Holder Opening Account

Accepts Login Accepts Register Accepts Register


Information Information Information

Valid Valid Valid


Login Registratio Registratio
Info n n

Account
Details Update
databas
Update Database e
Login Page

Display Error Message Display Error Message

The Functionality and Interaction of the Banking Application


The Welcome Page:
The Welcome page is the first page which will
displayed to a user who visits the banking application site of Money
Banks.The Welcome page will display a welcome message with the
information about the company.

The page will also display a counter indicating the


number of users who have visited the site.The Welcome page uses servlets
to display the number of viewers who have visited the page.Since servlets
have been used to create the Welcome page.

An Introduction to Servlets:
Servlets are Java programs that can be deployed on a Java-
enabled Web server to enhance and extend the functionality of the server.

In addition to displaying dynamic pages, servlets can be used to process


data at the server end. Transaction data can be processed either on client
side or the server side. Client-side processing is performed on client
browsers. Consider that you need to ensure that all the mandatory fields on
the logon screen displayed to a user are filled. This can be done on the
client side by using scripting languages, such as JavaScript. If the user has
provided the required information, the logon information will be sent to the
server. The verification of the logon information will be done at the server
side.

The interaction between the server and a client


On the Web, a client, which is usually a browser, sends a request for
a servlets to the server. The request is sent as an HTTP request that contains
the URL of the servlet. The servlets on the server runs in response to an
HTTP request.The servlets produces an HTML page that is returned to the
client.

The interaction between the server and a client is illustrated in the


follwing figure.

Client Server

The Advantages of Servlets:


 Servlets are loaded in the memory when they are executed for the
first time. During subsequent requests, the servlets don’t need to be
loaded again. This increases the efficiency of the server .In addition;
servlets are executed within the address space of the Web server.
Therefore, creating separate processes for handling different client
requests is not required.

 Since servlets are written in java, they are platform-


independent.Several Web servers from different vendors support
servlets API.Therefore, servlets programs can run on these servers
without requiring recompilation.

 Since servlets are written using java, all the features of Java library
classes are available to them.They can use Java API for tasks such
as networking and URL access, multithreading, database
connectivity, internationalization, remote method
invocation(RMI),and object serialization.

The GET and POST Methods:

When the client sends a request to the server, the client can also pass
additional information with the URL to describe what exactly is required as
output from the server by using the GET and POST methods.

The request from the client to the server contains the following
information:

 The protocol to be used for communication


 Whether the method GET or POST is to be used
 The URL of the requested document
 A query string that contains such as login and registration details

The difference between the GET and POST methods is that the
information, if any, sent with the request to the server is visible on the
browser while using the GET method. Therefore, sending requests to the
server by using the GET method can be risky.

To overcome this disadvantage, you can use the POST method to send
HTTP request to the server. The POST method sends the data as packets by
using a separate socket connection. When data is transferred in the form of
data packets, the data is hidden from the viewers. The disadvantage of
POST method is that it is slower than the GET method.

Creating the Counter Servlet:


The first page of the online banking application at Money Banks
displays the Welcome message to the viewers. A counter is also displayed
indicating the number of viewers of this page.

The Welcome page is the first page to be displayed to


a user who visits the banking application site of Money Banks. The
Welcome page will display a welcome message with the information about
the company.

The page will also display a counter indicating the number of users who
have visited the site.The Welcome page uses servlets to display the number
of viewers who have visited the page.Since servlets have been used to
create the Welcome page.

An Introduction to JSP:
Java Server Pages (JSP) is a technology used to create dynamic
content on the Web. With the spread of the Internet and increasing number
of users registering with Web sites, the static pages developed using HTML
have became obsolete. Consider an example. A Web site displays a
Welcome message along with the name to the registered user when the user
logs on. Imagine that a static HTML page is developed for each user. In this
scenario, when a user logs on, the server looks for the HTML page of the
user and sends the page back to the client. If there are thousands of users,
the server will take considerable amount of time to search for a user’s
HTML page. Therefore, the disadvantages are delay in sending the
response; development time; and the increased probability of error. The
solution lies in using a dynamic Web page.

The Differences between JSP and Servlet:

 Any change required in presentation and business logic necessitates


recompilation of servlets. This is because the servlets tie up both an
HTML file for the static content and java code for the dynamic
content, to handle presentation and business logic. On the other
hand, JSP allows Java code to be embedded directly into an HTML
page by using special tags. JSP files are automatically compiled and
loaded onto the server. Therefore, any changes made to either
presentation or business logic in a JSP is implemented automatically
whenever the JSP page is loaded.

 Servlet programming requires extensive coding. In addition, there is


no scope of division of labour between designers of static content
and developers of dynamic content during servlets development or
servlet modification. However, a JSP page facilitates both Web
developers and the Web designer to work independently since JSP
enables separate placement of the static and dynamic content.

The Life Cycle of JSP:


HTTP Request for JSP
Browse
r Server

Yes Corresponding yes


No
Servlet class exists

Compiles the Servlet class

Loads the Servlet class

Sends response to the browser

When a client browser sends a request to the server, the server


recognizes the request for JSP files by the file extension. The server
compiles and converts the JSP page into a servlet class. The server calls a
process called page compile to convert the JSP page into a servlet. The
process creates a servlet class and builds a service () method by extracting
contents of the .jsp file. All the HTML tags in the JSP page are wrapped in
the print method or the output methods. The java code snippets between the
JSP-specific tags in the .jsp file are copied into the servlet class. The JSP
tags are ignored. The elements of the JSP file, HTML, and Java code
appear in the servlet in the same order as they are in the JSP file. The
servlet is then compiled and run. The servlet creates an HTTP response,
which is sent to the client.

Writing a Java Program for Databases


Under this chapter we are going to discuss about the procedure for
creating a Java program that interacts with a database. For example there’s
an account holders database that contains the details of account holders in
Money bank. Now attempt to code a program that will display the details of
account holders after accepting the register ID from the user. The steps to
write such a program are given here:

1. Create the database and tables

2. Create the DSN

3. Load the driver

4. Establish database Connection

5. Execute SQL statements

6. Process the result

Creating the Database and Tables

The database that you need will store the details of the account holders.
Therefore, you’ll name the database as AcHolder_Info table. The Design of
the table is given here:

 Account_No Text

 Register_ID Text

 Balance Text

 Account_Type Text

 Branch Text

I’ve created the database and the table in MS Access and I’ll use this table
for database connectivity.
After creating the database, a DSN needs to be created.

Creating a DSN Source

The Data Source Name (DSN) contains information, such as the


location of the database server, database name, user name, and password to
be used to connect to the database server. The DSN also contains
information about the log file name to be used to store lengthy queries and
driver statistics.

You can create a DSN source by using the control panel. The steps to create
the DSN source are given here:

1. Double –click the Administrative Tools icon in the Control


Panel window.
2. In the Administrative Tools window, double-click the Data
Sources (ODBC) icon.
3. The User DSN tab page of the ODBC Data Source
Administrative dialog box is displayed. Click the Add button
to create the DSN source.
4. The Create New Data Source dialog box is displayed. A list
of drivers for which you can create a data source is displayed.
Since you’ll use the Access driver, you need to select
Microsoft Access Driver(.mdb) from the list.
5. The ODBC Microsoft Access Setup page is displayed. There
you have to set your DSN name.
6. Then by clicking select button you can set your path.
7. Click ok to finish the DSN setting.
8. Click the finish button to finish the connectivity process.

Loading the Driver

Before you can connect to a database from a java program, you


must load the database driver into the JVM. In a JDBC program, the JDBC
driver is loaded by calling the forName() static method of the Class class.
The forName () method takes one string parameter, which is the name of
the driver along with its package. For JDBC-ODBC bridge, this string is
“sun.jdbc.odbc.JdbcOdbcDriver”. Therefore the command will look like
this:

Class.forName (“sun.jdbc.odbc.JdbcOdbcDriver”);

The statement will load the JDBC-ODBC bridge driver. After loading the
driver, you need to establish the database connection.

Establishing the Database Connection

You can establish a connection with a database by using the


Connection object of the java.sql.Connection class. The Connection object
represents a connection with a database. You can use the getConnection()
method of the DriverManager class to establish a connection with a
database. This method attempts to locate the driver that can connect to the
database represented by the JDBC URL, which is passed to the
getConnection() method. The JDBC URL is a string that provides a way of
identifying a database. A JDBC URL consists of three parts:

<protocol>:<subprotocol>:<subname>

Here, the <protocol> attribute is always jdbc. The <subprotocol> attribute


is the name of the database connectivity mechanism. If the mechanism is
the JDBC-ODBC bridge, the <subprotocol> must be odbc. The subname
identifies the database. You can connect to a database by executing the
following statement:

Connection con=DriverManager.getConnection(“jdbc.odbc.DSNname”,””,””);

Notice that the last two arguments of the getConnection() method are
blank. These arguments identify the username and the password to provide
connectivity to the database.

Executing SQL Statements


You can use Statement object to perform queries with the database. The
methods of the Statement objects allow you to execute simple queries.
These methods are:

1. The executeQuery() method that executes a query and returns a


ResultSet object.
2. The executeUpdate() method that executes an SQL
INSERT,UPDATE, or a DELETE statement.

The createstatement() method of the Connection object is used to create a


Statement object.

The Home Page:


By clicking the HTML link in the Welcome Page “Click here
to continue” we just connect to the Home Page. Like every Web site there
is a home page, which is the central location where we can access other
pages of the application.

Here, we get several links. Those are follows:

 Current Accounts
 Savings Accounts
 Fixed Deposit
 Recurring Deposit
 Personal Loans
 Home Loans
 Consumer Loans
 Auto Loans
 Interest Calculator
 Foreign Exchange Rates
 Bank Branches
 Contact Us
 Log In
 Registration Page for Account Holder
 Registration Page for Non-Account Holder
The Output of the Home Page:

The registration Page for Account Holders:


Money Banks has many account holders. To enable these existing
account holders to register with the online banking application, the
development team decides to create a registration page. This registration
page will enable the account holders to register after it has accepted and
validated details such as account numbers and account types.

Registration Page For


A/C Holder

Check
Registratio
n
Display Error Message Update Database

Login Page

Show Account Details

Registration Page for A/C Holder

The technologies used to create the registration page are:

 Java Database Connectivity(JDBC)

 Java Server Pages(JSP)


The output of HTML page:
The HTML page, with the details filled in by the
user:
When the user clicks the Submit button the form is submitted to the JSP
page and the information is transferred to the JSP page by using the POST
method. The JSP page uses the JDBC API to validate the details. On
successful registration, the output as shown in figure is displayed.
If the information fails the validation test, the JSP page displays an error
message as shown in figure.

The Login Page:

Login Page

Check
Login

Login Page Account Details

Home Page
As the name suggests, the Login page of the online banking application at
Money Banks, Inc., will be used to accept and validate logon information
from the users. After validation, a user will be allowed to access the
application and perform transactions. The logon information generally
includes username and password. At Money Banks, the development team
decides to use the account number and password as logon information
because every account holder has a unique account number.

In this HTML page, two JavaScript methods have been used. These
methods are:

 Check ()

 home ()
Introduction about Java Script:

JavaScript is a scripting language. These languages make a Web page


dynamic. A script is a set of instructions that is interpreted by the Web
browser. A script allows the developer to capture keystrokes on the client
side, without any server interaction.

Java Script is available in two formats:

• Client-side: The client-side JavaScript is available to HTML pages


and it is displayed in a web browser. They are used to perform
client-side validations on Web Pages.
• Server-side: The server-side JavaScript is used to perform
validation at the server-end, such as communicating with a database
to validate the login in information.

Some of the characteristics of JavaScript are given as follows:

 JavaScript is event-driven. It can be programmed to respond to


user actions through input devices.

 JavaScript is platform-independent. JavaScript programs run


within an HTML document. The browser needs to support the
execution of JavaScript.

 JavaScript does not involve time-consuming compilation.


Scripts can be developed in a relatively short time.

 JavaScript is easy to learn. It does not have a complex syntax


and set of rules.

 JavaScript is object-based. An object-oriented program


handles a program as a collection of individual objects that are
used for specific task, and not as a sequence of statements that
perform a specific task.
 JavaScript supports constructs such as if..else, switch..case,
while, for, and do…while.

 Like Java, JavaScript is case-sensitive.

The syntax of JavaScript is similar to Java. Let us discuss something about


above two methods:

 The check () Method: The check () method is called when


the “View Account Details” button is clicked. This code will check
if the user has provided all the required information. If any of the
two text boxes, account no and password is blanked, an error
message is displayed. If the user has provided all the information,
the page is submitted.

 The home () Method: The home () method is called when


the user clicks the “cancel” button. It will display the Home page of
the banking application.

After all the fields are entered and the “View Account Details” button
is clicked the logon information is passed to the Login_page.jsp where it is
validating the database. On successful logon, the Login_page.jsp forwards
the request to the actDetails.jsp page.
The output of Login_page.jsp, showing Account
Details:
If the logon information matches the information in the database, the
request is forwarded to another JSP page, which is the actDetails.jsp. If the
user provides the incorrect information, the jsp page will not be forwarded.
Instead, the JSP page will again display the text boxes to accept logon
information from the user. The output of the unsuccessful logon page is
displayed below.

The output, after unsuccessful Login attempt


is displayed:
The registration Page for Non-Account Holders:

Based on the design of the banking application, the registration


page for non-account holders will enable the viewers to apply for opening
new bank accounts at Money Bank, Inc.

Registration Page For


Non-A/C Holder

Valid
Registratio
n

Display Error Message Update Database

Registration Page for Non A/C Holder

The Output of HTML page (Register_page.htm)


The HTML page, with the details filled in by the
user:
Register_page.htm is an HTML page that will accept and validate inputs
from the user. If the user has provided all the required information, the
inputs are forwarded to a JSP page, Register_page.jsp.

In this code, there are three are three user defined JavaScript methods.
These methods are:

 The year () Method : The year method is used to display


the years in the list box, which will enable the user to select the year
of birth. The method uses for loop and the document.write () method
to display years.
 The date () Method: The date () method is used to display
the day of a month in the list box, which will enable the user to
select the day of birth. The method uses the for loop and the
document.write () method to display a month.

 The verify () Method: This method is called when the user


clicks the Submit button. The verify () method checks whether the
user has provided all the required values in the page. If any of the
required values is missing, an error message is displayed. After
validating the inputs from the user, the HTML page forwards the
user information to the Register_page.jsp page for updating
Database.

The JSP code receives the information from the HTML page and
updates the Database. The output of JSP code is displayed below.
Output of the JSP code got the page to
verify the details to open a new account at
Money Bank Inc:

The Interest Calculator Page:


The Interest Calculator Page provides a utility to the user of the
Banking application to calculate interests’ payable at a specified rate on
a specified amount. The user will need to provide the following values:

 Principle amount
 Rate of interest
 Period in Months

We create this page using JavaBeans.

JavaBeans:
Java Bean is a software component created using Java and takes
advantage of all the security and platform independent features of Java.

The Advantages of JavaBeans:


 A Bean inherits all the benefits of “run-once, run-anywhere”
feature of Java.
 A bean can be designed to operate in different locales,making it
truly global.
 The configuration settings of a bean can be saved in a persistent
storage and restore at a later time.
 A bean can receive and send events to other objects.

Creating the Interest Calculator:


To create the interest calculator, we have created three files.
These files are:

• Interest_calc.htm: This is an HTML file that’ll accept and forward


values to a JSP page.

• Interest_calc.jsp: This JSP page will use the bean to calculate


interest.

• IntCal.java : This the bean sources file.


Interest_calc.htm Interest_calc.jsp IntCalc.java

The Working of interest the calculator is depicted

The output of the HTML page is, showing


the Interest Calculator page where we have
entered some sample values:
When the values in the HTML page are submitted, the JSP page calls
the beans to calculate the interest and it displays the calculated
interest. The calculated interest is shown in the below.

The output of the HTML page is displayed


the Calculated interest:
The Currency Exchange Calculator Page:

The Currency Exchange Calculator page will enable a user to


determine how much a specified amount of currency would value
when converted into a different currency. The JavaBeans Technology
is used to create the currency converted bean. The three files that are
used to create the exchange rate utility are:

• currExchange.htm
• currExchangeBean.jsp
• calc.java

The currExchange.htm page accepts values for conversion such


as currencies and amounts from a user. When submitted, the page
forwards these values to a JSP page, currExchangeBean.jsp. The JSP
page calls the calc.java bean to calculate the results. The interaction
between the three components of the currency exchange utility is
displayed in the figure below.

currExchange.htm currExchangeBean.jsp calc.java

The interaction between components of the


currency exchange calculator.

The Output of the currExchange.htm page:


When the Foreign Exchange Rates link is clicked on the Home Page, the
currExchange.htm page is displayed. A user can select currencies from the
list boxes.
When a user submits the currExchange.htm page by clicking OK button,
the currExchangeBean.jsp page displays the result to the user as shown in
figure.
The Bank Database
The database to hold information needs to be designed. The
development team designs a database called Bank, which will be created by
using Microsoft Access. The Bank database will hold the data of the bank
application. The tables of the database are explained as follows.

The Login_Info Table

The Login_Info Table will contain the logon information (such as the
password) about the account holders who have registered with the
application. The table structure is given below:

Field Name Data Type


Register_ID Text
Account_No Text
Password Text

The Ac_Requests Table

The Ac_Requests Table will hold the information of all the requests for
opening accounts at Money Banks. The Structure is given bellow.

Field Name Data Type


Request_ID Text
Branch Text
Account_Type Text
Title Text
First_Name Text
Middle_Name Text
Last_Name Text
Date_of_Birth Text
Work_Phone Text
Address Text
State Text
Zip Text
E-mail Text
Home_Phone Text

AcHolder_Info Table

The AcHolder_Info Table will contain information such as account type


and branch of the account numbers. The table structure is given bellow.

Field Name Data Type


Account_No Text
Register_ID Text
Balance Text
Account_Type Text
Branch Text

The TransCounter_Info Table

The TransCounter_Info Table will store the transaction information


of an account holder. The table structure is given bellow.
Field Name Data Type
Transaction_ID Text
Account_No Text
Transcation_Date Date/Time
Debit_Amount Currency
Credit_Amount Currency
Check_No Text

The Register_Info Table

The Register_Info Table will store information such as personal


details about account holders of Money Banks. The table structure is given
bellow.
Field Name Data Type
Request_ID Text
Register_ID Text
First_Name Text
Middle_Name Text
Last_Name Text
Date_of_Birth Text
House_No Text
Locality Text
City Text
PIN Text
E-mail_ID Text
Fax Text
Phone_Res Text
Phone_Office Text

The Relationship between Tables of the Bank Database


Login_Info AcHolder_Info
Register_ID Account_No
Account_No Register_ID
Register_Info Password Balance
Request_ID Account_Type
Register_ID Branch
First_Name TransCounter_Info
Middle_Name Transaction_ID
Last_Name Account_No Ac_Requests
Date_of_Birth Transcation_Date Request_ID
House_No Debit_Amount Branch
Locality Credit_Amount Account_Type
City Check_No Title
PIN First_Name
Email_ID Mid_Name
Fax Last_Name
Phone_res Date_Birth
Phone_office Work_Phone
Address
State
Zip
E_mail
Home_phone

Interfaces Used
 The Welcome Page

 The Home Page

 The Registration Page for Account Holders

 The Registration Page for Non-Account Holders

 The Login Screen Page

 The Account Details Page

 The Interest Calculator Page

 The Currency Exchange Page

Software Specifications

 Servlets

 JSP

 MS Access

JDBC

Tomcat6.0

Concepts Used in Banking Application

 Servlets and Deploying Servlets


 Servlets API and Handling Requests and Responses in Servlets.

 Cookies in Servlets and Creating Counter Servlets

 Servlets API Classes and Interfaces

 Java Database Connectivity (JDBC)

 JDBC API and JDBC Drivers

 Java Server Pages (JSP)

 Request and Response Cycle of JSP and JSP Tags

 HTML and Java scripts Event Handlers

 Java Beans Components Specifications

 Java Beans Properties and Testing Beans

Вам также может понравиться