Question
The exercises listed below are intended to provide an instructive way to get used to JavaBeans and JDBC. Complete all three exercises. Exercise 1 JavaBeans,
The exercises listed below are intended to provide an instructive way to get used to JavaBeans and JDBC. Complete all three exercises.
Exercise 1 JavaBeans, Self-Call
a) Write a page MiniAdd.jsp that carries out simple additions of two numbers. The JSP should:
- present a form where the user can specify two numbers,
- contain a submit button that posts back to the same page (i.e. miniadd.jsp),
- show the result of the requested addition, and also
- show the sum of all the additions carried out by the user so far.
Create and use a JavaBean (SumBean) to validate user input and to perform the addition. The same bean should also be used to store the sum of all additions. (Consider that the page does not receive input parameters when it is called the first time.)
b) Add a Reset Button to the page with which the user can reset the sum of all additions.
Exercise 2 JDBC, SQL, Address Management Application
Write a JSP based web application for address management, which allows to register and delete entries and to search for entries based on partial information given.
a) Create the table addresses with a structure as follows (in a server database of your choice).
Column Name | Type |
#id | INT UNSIGNED |
fname | VARCHAR(80) |
sname | VARCHAR(80) |
telephone | VARCHAR(30) |
mobile | VARCHAR(30) |
| VARCHAR(80) |
address | VARCHAR(100) |
postalnr | VARCHAR(10) |
town | VARCHAR(40) |
country | VARCHAR(30) |
Define id as the primary key for the table and set it as automatically incrementing for this column to guarantee a unique identity of id (as follows)
create unique sequence MY_ID_SEQUENCE;
(in the table definition: ID integer default next_value of MY_ID_SEQUENCE, ...)
b) Write a JSP Register.jsp, which provides a form to insert a new entry for a person into the table, and another JSP exRegister.jsp, which actually performs the required INSERT statement. Use a JavaBean AddressBean to check the validity of a record before inserting it into the database, i.e. check that at least a first name is given (a surname might not always be accessible to you in the case of persons known only by their nickname), and also either the number of a stationary or a mobile phone or an e-mail address was specified. In case of invalid information, redirect the request to Register.jsp and make sure that the user does not have to enter valid parts of the record again. Use the AddressBean bean to annotate those fields in the registration form, which caused the insertion of the record to fail, with a reasonable error message. If a new record was successfully added to the table using Register,jsp, redirect the request to the page DeleteAddress.jsp, which you are going to write in the next subtask.
c) Add JSPs DeleteAddress.jsp and exDelete.jsp. The JSP DeleteAddress.jsp presents a list of all entries each followed by a Delete button. The Delete button is linked to exDelete.jsp, which carries out the deletion in the database table. Take care not to exchange more information than required between DeleteAddress.jsp and exDelete.jsp.
d) If a new record was successfully added to the table using Register,jsp, redirect the request to a page SearchAddress.jsp. This page offers another form where the user can specify partial information concerning arbitrary fields the records in the addresses table contain. Carry out the SELECT statement corresponding to the information given in SearchAddress.jsp in a JSP exSearchAddress.jsp and display the result in SearchAddressResult.jsp. For selection of an address, combine the fields that specify the search in the way that seems suitable for you.
Exercise 3 JavaBeans to Encapsulate Application Logic
If not already done so, modify the Address Management application of exercise 2 such that all the application logic, particularly concerning database access is encapsulated in JavaBeans.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started