Sie sind auf Seite 1von 122

Developing

a Java Web Application in a Day



Step by step explanations with Eclipse Mars, Tomcat and
MySQL



Luciano Manelli

Copyright 2016 Luciano Manelli
All rights reserved

Author
Luciano Manelli was born in 1975 in Taranto (Italy). He graduated in Electronic
Engineering at the Polytechnic of Bari at 24 years of age and then he served as an officer
in the Navy. In 2012, he received a PhD in Computer Science from the Department of
Informatics, University of Bari - Aldo Moro. In the PhD, he analyzed Grid Computing and
published the results in international publications. He is contract Professor at the
Polytechnic of Bari (Course: Foundations of Computer Science), and at the University of
Bari - Aldo Moro (Course: Programming for Web). The author has fifteen years
experience, working in the field of computer science and information systems and he has
also experiences about the subject at Polytechnic of Bari, at University of Bari Aldo
Moro and at professional courses. He is professionally certified engineer, and in 2014 he
started working for the Taranto Port Authority, after working for 13 years for InfoCamere
SCpA. He wrote the book Fundamentals of Modern Information Technology (Italian
Edition Fondamenti di Informatica Moderna publisher ARACNE) in 2014 and the
book Web Programming in Java (Italian Edition Programmazione per il Web
publisher ARACNE) in 2015.

Contacts:
moderninformatics75@gmail.com
it.linkedin.com/in/lucianomanelli

Preface
This is a condensed version of Chapter VI (Web Application with Java and Eclipse)
from the book Web Programming in Java (Italian Edition Programmazione per il
Web publisher ARACNE).
This book has been written for students and for the professional, and it can serve as a
starting point for anyone who is beginning the study of Web Application in Java for the
first time. In the following text, Servlet, JSP, JavaBean and simple DAO are accurately
analyzed and implemented in Java, with a clear project evolution: from the configuration
of Eclipse Mars, JDK, MySQL and Tomcat to the execution and the testing on a browser
and the creation of the final package for the distribution on other machines. Everything is
integrated with explanations, java codes and screenshots to have a step by step evolution
of the web application. Let us try to do this in a day!

I think that everyone has to always follow their own dreams and fight for them

Luciano Manelli, Fondamenti di Informatica Moderna, ARACNE, 2014.



1. Index
1. Index
2. Introduction
2.1 MVC Model View Controller
2.2 Web Application, Servlet and JSP
3. How to install and configure MySQL 5.6 Community
4. Database Analysis, Design and Implementation for Web Application
4.1. How to create a MySQL Data Base for Web Application
4.2 MySQL Logical Schema and Reverse Engineer DataBase
5. How to configure Eclipse MARS (JDK and Tomcat)
5.1. How to configure JDK in Eclipse
5.2 How to configure Tomcat 8.0 in Eclipse
6. How to create a Dynamic Web Project in Eclipse
6.1. How to create a JSP and run a project in Eclipse
6.2. How to create a Servlet 3.X in Eclipse
6.3. How to create a Class in Eclipse
7. Implementation of the Java Project for Web Application
7.1. How to write and manage forms: the Eclipse Java Project runs on a browser!
7.2. JavaBean
7.3. Request Redirect vs Dispatcher
7.4. Request vs Session
7.5. Connection to MySQL DataBase, Commit and Roll-Back
7.6. Examples of error handling in java Web Application
8. Web Application ready for the distribution on Tomcat
9. Conclusion
10. Bibliography
11. Index of Figures

2. Introduction
The study of web application plays the most important role in web programming and it
can be considered the cornerstone of companies technology. In fact, all the modern
technology both in private and government companies is based on automation systems,
both in terms of lower costs (one application on a server costs less than n applications on
individual PCs) and in terms of sharing information in internet, intranet and extranet
companies web site.
The aim of this text is to learn how to set up a web project in Java technology. We shall
use Java because it is free, standard and there are many (free) libraries on the web. We
shall create the database in MySQL, and implement all the procedures to develop a web
application using Eclipse, analyzing many issues in a clear and simple way, providing the
principles for developing complex applications. We first need to download the necessary
(free) software:
Eclipse MARS;
MySQL;
Driver MySQL;
Tomcat 8.0.

To follow this dissertation is only necessary to have minimum skills on algorithms,
programming, java, html and database.
2.1 MVC Model View Controller
The more used pattern in application development is the MVC (Model-View-
Controller). This pattern was described by Xerox, for the first time, in several publications
in the late eighties. The most important aspect is the separation into three distinct
components:
Model: it is related to the application logic and persistence of data manipulation;
View: it is related to the presentation, that is the interface with the end user;
Controller: it is related to the processing of requests.

This level of separation is important both for reasons of stability and security of the
application.
2.2 Web Application, Servlet and JSP
A Web Application consists of a set of Servlet, pages html/xhtml and jsp, classes, and
other components, which can be installed and run inside a container (Application Server),
which presents a JVM (Java Virtual Machine). A web application is mapped through a
hierarchy of directories stored on the file system and usually exported as war, jar or ear.
Assuming that the root folder of our project is company_management, it will be deployed
to the webapps directory of Tomcat. In the root may be other directories, including the
WEB-INF directory (accessible only by the application server), which contains the
web.xml, the compiled classes folder, and the libraries folder.
We shall use Tomcat as Web Application Server: it is able to handle the latest versions
of the Servlet (from 2.5 to 3.1) and JSP pages (but also EJB, or frameworks such as Struts
and Web Services which Axis).
JSP (Java Server Page) technology allows us to easily create html/xhtml pages, which
have both static and dynamic components (as abstraction of Java servlets). The dynamic
code in Java is contained in <%%> and precompiled before sending the response to the
client.
Servlets are Java classes, which run in Servlet Container (e.g. Tomcat or JBoss) and are
exposed as standard web resources. These classes process data from the html form and
handle requests and responses for one or more clients. The 3.x standard (in Java EE
standard) is the latest version of the Servlet specifications (JSR 315). A servlet
corresponds to the Controller in the MVC architecture, and it implements many complex
functionality. We can use a single servlet to handle different behaviors or many servlet for
each behavior. We shall use in the text a single Servlet, which presents different behaviors.
Briefly, a client sends a request to a servlet (in a web application server), the
Servlet gets instantiated (only the first time), starts a thread to handle the communication
and builds the response which is forwarded to the client; if the Servlet has already been
loaded, it will create an additional thread associated to the new client. The Servlet has
usually no algorithmic code inside, but it is delegated to other classes. Request and
Response are managed by the interfaces javax.Servlet.http.HttpServletRequest (which
obtains information from the client environment) and
javax.Servlet.http.HttpServletResponse (which sends response to the client). Another
component (javax.Servlet.ServletContext) allows to find the reference to the context of an
application.
Servlets have a life-cycle characterized by the following elements and methods:
initialization of the servlet (method init()), called, only the first time, from the
Servlet Engine;
response to POST requests (method doPost(HttpServletRequestrequest req,
HttpServletResponseresponse res));
response to GET requests (method doGet(HttpServletRequestrequest req,
HttpServletResponseresponse res));
destruction of the servlet contex (method destroy()).

Servlet 3.X represents the state of the art of the Servlet technology. The use of
annotations is one of the most important innovation within a web application: it is a way
of adding metadata in the servlet source code as an alternative to XML technology
contained in web.xml).

We shall create a single servlet, which will have different behaviors depending on
parameters from data entry forms. The actions will be consequences of method calls
(method doGet or doPost).

After a preliminary analysis of the hypothetical requirements of a customer, for
example, we suppose to develop a web application (called Company_Management) with
the aim to save and manage a number of companies and their employees.
3. How to install and configure MySQL 5.6 Community
Let us start! It is about nine am!
MySQL (now Oracle MySQL) is a powerful relational database (RDBMS), which
works on both Linux/Unix and Windows. It is very useful for the creation and the
management of DataBase dor developing web applications. It is a free software and,
therefore, it is used both as a database for simple sites and for professional applications
(for esample Liferay). The following steps explain the installation and the configuration of
MySQL on Windows OS.
Now, we shall install MySQL!
Go to the Oracle site http://www.mysql.it/, and download these two main elements:
MySQL Community Server (http://dev.mysql.com/downloads/mysql/): open
source DB;
MySQL Workbench (http://dev.mysql.com/downloads/workbench/): open source
environment used for the creation and management of the DB (schemas, tables,
etc.).

We shall choose the download installations for Windows!
The downloaded files are:
server: mysql-installer-community-5.6.21.1.msi;
workbench: mysql-workbench-community-6.2.3-winx64.msi.

Now, step by step, we shall install the server and the workbench (I tested them on
Windows 8 and Windows 7)!

First, Licence.

Figure 1. MySQL Server Installation.


Figure 2. MySQL Server Installation, licence.

Now we shall follow the wizard steps.

Figure 3. MySQL Server Installation setup type.


Then the installation starts.

Figure 4. MySQL Server Installation - Installation.

The last step.


Figure 5. MySQL Server Installation installed.

Now we shall configure some parameters (i.e. port number 3306).

Figure 6. MySQL Server Installation configuration.

The wizard asks for the administrator password setting. We shall use simply root for
development environment.
Figure 7. MySQL Server Installation password setting.

Then we shall set MySQL as Windows Service.

Figure 8. MySQL Server Installation Windows Service.


Al last, the previous configurations are applied.

Figure 9. MySQL Server Installation Server configuration.

The wizard tests the server connection.


Figure 10. MySQL Server Installation test server connection.

Last installation steps.

Figure 11. MySQL Server Installation last steps.

The end.
Figure 12. MySQL Server Installation end.

Now, we shall install the workbench, with the Wizard.

Figure 13. MySQL Workbench Installation.

We shall choose the complete installation.


Figure 14. MySQL Workbench Installation - setup.

The installation starts.

Figure 15. MySQL Workbench Installation - installation.

The end.
Figure 16. MySQL Workbench Installation - end.

Finally, the workbench is running.

Figure 17. Workbench environment.


4. Database Analysis, Design and Implementation for Web Application
Now, we shall design the DB Company_Management, in order to save on DB and
manage a set of companies and their employees.
The preliminary analysis leads us to define two entities: Company and Employee: a
company can have from 0 to n employees and an employee may be employed to only one
company. A company has the following (simple) fields:
idcompany: identification number (for example number) of the company (key);
company_name: name of the company;
phone: phone number;
email: company email;
insert date.

The employee (Employee) will instead have the following fields:
idemployee: identification number (for example Social Security Number (SSN)) of the
employee (key);
surname;
name;
badge or serial number;
insert date.

Moreover, we also need to have relationships between these two tables: in fact an
employee works for a company and a company has many employees. So, the Employee
entity will have a foreign key linked to the attribute idcompany of the the Company entity.
4.1. How to create a MySQL Data Base for Web Application
Now it is possible to create our Data Base. We shall connect to the Server using the
Workbench.

Figure 18. Connection to the Server using the Workbench.

Afterwards, the screen will show the standard parameters for connection. Click okay!

Figure 19. Parameters for connection.

Now, set to root the password and confirm!

Figure 20. Connection to the Server password setting.

Now the workbench environment is ready, and we can start.

Figure 21. Workbench environment.

Now we shall create a new schema. Go to SCHEMAS area, and click the right
mouse button.
Now, we shall select Create Schema on the context menu.

Figure 22. Workbench, how to create a new Schema.

Now we shall create the Schema: company_management.


Insert company_management in the name and click OK!
Then, the script is executed.






Figure 23. Workbench, how to create a new Schema creation script execution.

Once we create the DB, we shall create the tables, which are:
Company table;
Employee table.

The simplified design will be done in tabular form according to the conceptual and
logical design (not detailed in the text).

Schema: company_management



Now we shall create the tables.
Select our schema, then click the right mouse button on the tables.
Now, we shall select Create Table on the context menu.
Insert company in the Table Name!

Figure 24. Workbench, how to create a table.

Now, we shall create fields and define key fields (PK) and non-zero fields (NN). At
first, we can create the key field idcompany and the field company_name.
Figure 25. Workbench, Table name e field insertion.

Finally, the script is executed.







Figure 26. Workbench, how to create a Table creation script execution.

Once the table is created, we can edit it using the screwdriver right icon from the left
menu of the table.


Figure 27. Workbench, how to modify a Table.

You can also display a table with its values and run queries, using the table right icon
from the left menu of the table.

Figure 28. Workbench, how to analyze a Table (query).

Now, we can complete the table defining all fields (idcompany, company_name, email,
phone, date_ins). The following figure shows the table company.

Figure 29. Workbench, company table.

Now, we can create the table employee defining all fields defined in conceptual
design (idemployee, name, surname, badge, date_ins and the foreign key to the company
FK_company). The following figure shows the table employee.

Figure 30. Workbench, employee table.

Now, it is necessary to define constraints between the employee and his company.
Define then the FK_company as a foreign key, setting the tab Foreign Keys!

Figure 31. Workbench, how to define a foreign key.


Figure 32. Workbench, definition of foreign key.

Figure 33. Workbench, how to create a Foreign Key creation script execution.

If we wanted, we could also export scripts for creating diagrams and tables with a
simple operation (right click on the schema or table, Copy to Clipboard, Create
Statement).

Figure 34. Workbench, how to export a creation schema script.

The exported script of Schema is:



CREATE DATABASE `company_management`

Figure 35. Workbench, how to export a creation table script.

The exported scripts of tables are:



CREATE TABLE `company` (
`idcompany` varchar(16) NOT NULL,
`company_name` varchar(45) NOT NULL,
`phone` varchar(16) NOT NULL,
`email` varchar(45) NOT NULL,
`date_ins` date NOT NULL,
PRIMARY KEY (`idcompany`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE `employee` (
`idemployee` varchar(16) NOT NULL,
`name` varchar(45) NOT NULL,
`surname` varchar(45) NOT NULL,
`code` varchar(45) NOT NULL,
`FK_company` varchar(16) NOT NULL,
`date_ins` date NOT NULL,
PRIMARY KEY (`idemployee`),
KEY `FK_company_idx` (`FK_company`),
CONSTRAINT `FK_company` FOREIGN KEY (`FK_company`) REFERENCES
`company` (`idcompany`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
4.2 MySQL Logical Schema and Reverse Engineer DataBase
Finally, with Workbench we can start from the definition of the tables (after the
conceptual and logical analysis), or we can start from the definition of the entity-
relationship diagram and then get the tables. Finally, we can obtain the graphic logical
design of the DB from existing tables with the reverse engineer tool. In the last case, we
can simply go to the main page of the Workbench and select from the tab Database the
Reverse Engineer option.

Figure 36. Workbench, reverse engineer.

Then just follow the instructions of the wizard.


Figure 37. Workbench, reverse engineer: connection to the DB.



After selecting the DB, enter user / password, and, finally select the scheme.


Figure 38. Workbench, reverse engineer: user/password.

Figure 39. Workbench, reverse engineer: script execution.

Therefore, we can then get the logical schema, to print or save.


Figure 40. Workbench, tables schema of reverse engineering.









The system also automatically inserts the default indexes (primary and foreign keys).

Figure 41. Workbench, Workbench, tables schema of reverse engineering with indexes.

We have just finished! It is about ten am!


5. How to configure Eclipse MARS (JDK and Tomcat)
We need to download the appropriate IDE for working in Java. The most popular and
free IDE is Eclipse: its latest version (Mars) is available at www.eclipse.org.
Now, we shall download the following zipped file: eclipse-jee-mars-R-win32-
x86_64.zip. After downloading it, we do not need to install Eclipse, but it is only
necessary to unzip the compressed file (I usually choose the directory C: /). The unzipped
files are present in the extracted folder eclipse, which we can rename into mars (the
name is irrelevant, but may be useful to distinguish different Eclipse versions, we can have
many version of Eclipse on our machines). This will be our working folder of the IDE.
Eclipse simply run by simply double-clicking the eclipse.exe executable file.

Figure 42. Eclipse, files in the extracted folder eclipse Mars.


As soon as we start the executable file, the IDE asks what is the workspace (i.e. the
project folder): I usually change the standard directory and choose the directory C: /.

Figure 43. Eclipse, workspace.

The initial screen is the following one.



Figure 44. Eclipse, initial screen.

5.1. How to configure JDK in Eclipse
We can work with Java in Eclipse environment, but we have to install and configure the
JDK - Java SE Development Kit. So, download the latest version from:
http://www.oracle.com/technetwork/java/javase/downloads/index.html.
I choose to download the following executable file for Windows: jdk-8u65-windows-
x64.exe.
So we shall click the download button and accept the license, than we start to download
the chosen version of JDK.

Figure 45. JDK Download.


Now, install the executable file! Then we shall configure the IDE, from window -
preferences - JAVA / Installed jre and select (or search on the PC) the downloaded jdk.

Figure 46. Eclipse, JDK configuration.


5.2 How to configure Tomcat 8.0 in Eclipse
All applications run on a server. In this case, we shall use Tomcat, which is one of the
most versatile server. So, download the latest version from:
http://tomcat.apache.org/
I choose to download the following zipped file for Windows: apache-tomcat-8.0.14-
windows-x86.zip. After downloading it, we do not need to install Tomcat, but it is only
necessary to unzip the compressed file (I usually choose the directory C:/). The unzipped
files are present in the extracted folder apache-tomcat-8.0.14, which will be the
distribution/ operation /delivery folder. We shall also use this folder of Tomcat and its
instances for the development of our web application. A very business situation includes
different environments (such as development, test and distribution/operation/delivery), so
it is always necessary to maintain consistency between the server versions to prevent bugs
or different behaviors.
It is necessary to configure the server in the Eclipse IDE. Go to the tab server,
automatically it asks the configuration of a new server. We can click on that link, select the
Tomcat server 8, and follow the wizard required.

Figure 47. Eclipse, new server configuration.


Figure 48. Eclipse, Tomcat selection.

Figure 49. Eclipse, Tomcat server and installed JRE.

We can configure a server even from File New Server.




Figure 50. Eclipse, another way to configure a server in Eclipse.

After configuring the server, we can go on the tab server, the server will appear just
configured. We shall now click the right mouse button, open the context menu and start
the server.


Figure 51. Eclipse, how to start the selected server.

If we go on the browser, we can see the Tomcat server that is activated by typing the
following URL in the address bar (URL of the server followed by the name of the
application):

http://localhost:8080/ Web_Application_name
6. How to create a Dynamic Web Project in Eclipse
It is about ten thirty am!
Now we shall start the steps for creating a Java web application.
Go on the File menu and select New and then Dynamic Web Project.


Figure 52. Eclipse, how to create a web project.

The related wizard starts. We shall enter the name of the project
company_management and leave unchanged the other parameters.



Figure 53. Eclipse, configuration of a web project.

In particular:
Project name: it must be a valid identifier of the project for cross-platforms, so it is
advisable using lower-case name, with alphanumeric elements;
Use default location: it defines a directory where creating the web project (we
can leave to default, or specify a new folder);
Target Runtime: defines the application server to be used where deploying the
application (e.g. Tomcat);
Configuration: select the configuration to use, which usually is the used
application server (e.g. Tomcat). The Servlet 3.X uses @WebServlet deployment,
while the Servlet 2.5 uses web.xml deployment.
Then, we shall define the folders for source files (src) and compiled files (classes).

Figure 54. Eclipse, configuration of src e classes folder for a web project.

Finally, we shall define the context root of the application and the context directory.
For simplicity, we associate the same name in all the elements of configuration.


Figure 55. Eclipse, context root and context directory configuration.

In particular:
Context Root: it identifies access URL of the web application. In this case it will
be http://localhost:8080/company_management.
Content Directory: it is the directory that contains all components of the Web
Application, which will be deployed into the server, and it is the root of the
project.

Note that in this passage the creation of web.xml is checked. The automatic creation of
the deployment descriptor is deprecated because the descriptor is no longer necessary for
the latest applications (Servlet 3.X). The issue is related to the ability of working with
legacy applications developed with Servlet 2.X. never.
Below, the created project.


Figure 56. Eclipse, created web project.
6.1. How to create a JSP and run a project in Eclipse
The first step for working with Java and Eclipse is the creation of a JSP (Java Server
Page). We can just go to the File menu - New - JSP files.

Figure 57. Eclipse, how to create a JSP.

We can enter the name of the JSP.


Set the name hello.jsp.


Figure 58. Eclipse, JSP configuration.

Eclipse creates the following jsp page, automatically inserted in the created project.

Figure 59. Eclipse, JSP script.

Now we shall get to work by inserting the text HELLO WORLD! in the body and in
the title of the created JSP.


Figure 60. Eclipse, how to modify a JSP script.

In order to see the results of the web page it is enough to start the server. We can select
the server, click the right mouse button and, at last, click the green play button located on
the context-menu.

Figure 61. Eclipse, how to run the server.

The server state passes from Stopped to Started.


Figure 62. Eclipse, started server.

We can also select run from the menu, then select Run As and then Run on
Server from the context-menu.

Figure 63. Eclipse, run from menu.

Further, we can select the green button play from the menu, and then Run As e
Run on Server.

Figure 64. Eclipse, run from play button of menu.

Finally, we can select the project, click the right mouse button and, from the context-
menu Run As and Run on Server.
Figure 65. Eclipse, Run from project.

If the server is yet not set, we can choose it from the context-menu.


Figure 66. Eclipse, selection of the server.

The last step is the configuration of the project company_management on the selected
server.


Figure 67. Eclipse, web application configuration on the server.

Now we shall view the web page on Eclipse!



Figure 68. Eclipse, hello.jsp web page.


We can also view the web page through any browser. For example Chrome.

Figure 69. Chrome, hello.jsp web page.

If we see the web.xml file, we can fill the file hello.jsp between the welcome-file-list: in
this way, the first page, that we see when we open the application, is one of those on the
list of the welcome-file-list.

Figure 70. Eclipse, welcome file list.

Now, we shall consider index.jsp the welcome page, and then every time we open the
application at its URL (http://localhost:8080/company_management/) the index.jsp page
will be called.
6.2. How to create a Servlet 3.X in Eclipse
Now, we shall create a new Servlet! We can just go to the File menu - New - Servlet.

Figure 71. Eclipse, how to create a Servlet.

Then, we can define the package company_management.Servlet (it is possible to insert


different folders). We shall call our Servlet: FirstServlet (conventionally Class and Servlet
names are capitalized).


Figure 72. Eclipse, servlet name and package configuration.

Finally, it is important to check the methods init and destroy in a Servlet.




Figure 73. Eclipse, servlet methods definitions.

We can see the just created Servlet with the main methods in the following screen.


Figure 74. Eclipse, Servlet script.

We can immediately see that Eclipse generates the following annotation:



@WebServlet(/FirstServlet)
6.3. How to create a Class in Eclipse
Now, we shall create a new Class! We can just go to the File menu - New - Class.


Figure 75. Eclipse, how to create a class.

Then, we can define the package company_management.utility (it is possible to insert


different folders). We shall call our Class: FirstClass (conventionally Class and Servlet
names are capitalized).



Figure 76. Eclipse, class name e package configuration.


We can see the just created empty Class in the following screen.



Figure 77. Eclipse, Class script.
7. Implementation of the Java Project for Web Application
It is about eleven am!
7.1. How to write and manage forms: the Eclipse Java Project runs on a browser!
We shall start to manage a form and, then, its control in a Servlet. Now, create the jsp
page with the following fields: name and idemployee. We shall create the formExample.jsp
by clicking the right mouse button on our project, then New, and JSP File.

Figure 78. Eclipse, how to create a JSP for our web application.
Figure 79. Eclipse, name of JSP.

The Java code is:



<%@ page language=java contentType=text/html; charset=ISO-8859-1 pageEncoding=ISO-8859-1%>
<!DOCTYPE html PUBLIC -//W3C//DTD HTML 4.01 Transitional//EN http://www.w3.org/TR/html4/loose.dtd>
<html>
<head>
<meta http-equiv=Content-Type content=text/html; charset=ISO-8859-1>
<title>Form Example</title>
</head>
<body>
<form action=/company_management/FirstServlet method=post>
name:<input type=text value= name=name/>
<input type = submit value=POST SUBMIT>
</form>
<form action=/company_management/FirstServlet method=get>
idemployee:<input type=text value= name=idemployee/>
<input type = submit value=GET SUBMIT>
</form>

</body>
</html>


There are two forms, characterized by two methods (POST and GET), two different
input fields and two submit buttons.

Figure 80. Eclipse, form JSP Java code.

Figure 81. Browser Chrome, form.

The Servlet works with two methods: doGet and doPost, which manage messages
coming from the request (HttpServletRequest), using the method:
request.getParameter(idemployee). If we want to see the data successfully processed by
the Servlet, we can simply use the command System.out.println, that allows us to view
data on the Eclipse console. In the following example it is also used a method of the
Response to display on the browser the sent parameters: response.getWriter(). See the
following Java code of FirstServlet.java.

protected void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {


System.out.println(GET);
String idemployee = request.getParameter(idemployee);
System.out.println(idemployee (GET):+idemployee);

PrintWriter out = response.getWriter();
java.util.Date today = new java.util.Date();
out.println(<html><body> + today +
GET parameter: + idemployee + </body></html>);
}


protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
System.out.println(SONO IN POST);
String name = request.getParameter(name);
System.out.println(name (POST):+name);

PrintWriter out = response.getWriter();
java.util.Date today = new java.util.Date();
out.println(<html><body> + today +
POST parameter: + name+ </body></html>);
}

Figure 82. Eclipse, doGet and doPost in a Servlet.

If we click the first submit button POST SUBMIT Figure 81 (which sends a POST
message to the servlet), we get the following result on the Eclipse browser and on the
browser.

Figure 83. Eclipse, POST result on the Eclipse browser and on the browser.

If we click the second submit button GET SUBMIT Figure 81 (which sends a GET
message to the servlet), we get the following result on the Eclipse browser and on the
browser.

Figure 84. Eclipse, GET result on the Eclipse browser and on the browser.

Now we shall create the two JSP form (without considering the layout of the html
page)!

The company fields are:
idcompany [varchar(16)];
company_name [varchar(45)];
phone [varchar(16)];
email [varchar(45)];
date_ins [date].

The employee fields are:
idemployee [varchar(16)];
name [varchar(45)];
surname [varchar(45)];
badge [int(10)];
FK_ company [varchar(16)];
date_ins [date].

Note that the date is important for the system administrator and it is not present in the
form!
Moreover, the maximum length of strings requires a control, which can be done in the
html form through the use of maxlength attribute. This attribute specifies the maximum
number of characters which can be filled in an form input field.

Finally, we shall use the POST method to send the form.

Now create two new jsp pages and the Servlet (we know how to do it!):
formCompany.jsp;
formEmployee.jsp;
CompanyManagement.java.

The following screenshot is for the Eclipse form of the Company.
Figure 85. Eclipse, form companyForm.jsp.

The following screenshots are for the browser form of the Company (empty and filled
in).

Figure 86. Browser, empty form companyForm.jsp.


Figure 87. Browser, filled in form companyForm.jsp.

The following screenshot is for the form of the Employee.

Figure 88. Eclipse, form employeeForm.jsp.

The following screenshot is for the browser form of the Employee.


Figure 89. Browser, empty form employeeForm.jsp.

We can see that the employee presents a hidden field named FK_company. This field is
filled in by the idcompany of Company Entity once inserted the company. We shall fill in
this value when the company form is completed and sent to the servlet.

We shall do this with implementing a system of sessions.

See the following piece of Java code of the Servlet: in console, we can view the
parameters.

In order to distinguish the two entries from two different forms, from server side it is
possible to insert a hidden field (in a very simply way!) to understand if the submit form
comes from the company form or from the employee form and then manage it accordingly
by saving its fields. This operation is clear observing the console results!

We shall use the field whatsend, which helps us to establish the behavior in the servlet,
as we decided to use a single servlet. So, we shall have several whatsend hidden fields, in
our case:
company;
employee;
savecompany.
Figure 90. Servlet CompanyManagement.java and console.
7.2. JavaBean
It is twelve oclock!
Once we have taken values from the form, we need to manage them saving them into
Database. Therefore, according to the MVC pattern, it is necessary to create and use an
object which will be passed to a DAO (Data Access Object) class for saving data into
Database. This object can encapsulate many objects into a single object, which can be
serialized.

Now, we need to create and instantiate a new object (JavaBean), which sets and
maintains the status of its variables during the time of use. This class presents only the get
and set methods of its variables (pattern of data encapsulation).
We shall start with the creation of a new class.

Figure 91. JavaBean class creation.


Once we created a new class, we shall implement the java.io.Serializable. Then, the
IDE content assist shows automatically a suggestion, which suggests to enter an ID (Java
(TM) Object Serialization Specification) to allow serialization and de-serialization for
persistence. Therefore, it is useful to use the Eclipse suggestion and to create
automatically an ID serialization.

Figure 92. JavaBean Version ID creation.

Figure 93. JavaBean Version ID created.

Now, we shall enter all fields of the company and the Eclispe IDE helps us to
automatically generate the get and set methods (click the right mouse button class, then
Source, and Generate Getters and Setters..).

Figure 94. How to Generate Bean Getters and Setters step 1.

Figure 95. How to Generate Bean Getters and Setters step 2.

Then, we shall get the class with the get and set methods showing in the following Java
code and screenshot:

package company_management.bean;

/**
* @author manelli
*
*/
public class EmployeeBean implements java.io.Serializable {

/**
*
*/
private static final long serialVersionUID = -1549250885233338087L;

private String idemployee ;
private String name;
private String surname ;
private String badge ;
private String fk_company;


public String getIdemployee() {
return idemployee;
}
public void setIdemployee(String idemployee) {
this.idemployee = idemployee;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getSurname() {
return surname;
}
public void setSurname(String surname) {
this.surname = surname;
}
public String getBadge() {
return badge;
}
public void setBadge(String badge) {
this.badge = badge;
}
public String getFk_company() {
return fk_company;
}
public void setFk_company(String fk_company) {
this.fk_company = fk_company;
}



Figure 96. Eclispe, CompanyBean.java.

Now, we shall do the same operation for the employee Bean.


Figure 97. Eclispe, EmployeeBean.java.

Now we need to link the two beans. The employee is part of the company and the
company can have from 1 to n employees.
How can they be related each other?
Obviously, it is sufficient adding an additional variable to the company bean, which
identifies the set of employees!
We shall use an ArrayList of EmployeeBean objects in the Company bean as shown
below:

private ArrayList< EmployeeBean > companyEmployees;


Then, it is necessary to generate the get and set method.
The java code into quotation marks (<>) represents the use of java generics.
7.3. Request Redirect vs Dispatcher
It is about ten past one! Five minute for a sandwich!
We shall use another object to return and maintain an object (with state!) from the
Servlet to the JSP. The server side presents two main method: redirect and dispatch. The
first is the following code:
response.sendRedirect(http://www.aracneeditrice.it/);


In such case, the Servlet does a redirect to a specific URL without taking memory of the
current state of its parameters (an example is the return to the home page of a site).

In the case of dispatch, it is assumed that the server does something else; in fact, the
browser displays a particular JSP and passes some parameters (such as those in session or
request); and the end-user does not know that the content of a JSP page is rendered in the
browser. In this case, the standard syntax is:

ServletContext sc = request.getSession().getServletContext();
RequestDispatcher rd = sc.getRequestDispatcher(/company.jsp);
rd.forward(request, response);


The servlet uses the application context and then transfers control to the JSP. In the
following text, we shall use mainly the dispatching method.
For example, we shall insert two new links: one to the home page and the other to the
employee page. We shall link the home page with a redirect and the JSP employee page a
dispatcher. In the following screenshot, it is possible to see the two links.

Figure 98. JSP links companyForm.jsp.

In the Servlet we shall use the doGet method to manage the request, as the Servlet is
called via a direct link (the html form GET method) and not via the submit form (the html
form POST method).
Figure 99. JSP links - employeeForm.jsp.

Figure 100. JSP links homepage.jsp.


7.4. Request vs Session
It is about ten to two!
Now we can connect the two elements, but we also need to maintain the state of the two
analyzed bean. This is possible using request or session. The difference between request
and session is based on the scope of the attributes. The request is canceled as soon as the
response is committed to the client, while the session ends with the end of the session (for
example, the browser is closed). We shall study and use the session. In fact, the use of the
request can generate the possibility of losing data in the event that we work with
frameworks where different layers of software are present.
When we create a new session, the server allocates a memory location, which will
contain data, which the users browser knows. Practically, a cookie is set in the browser
with an identification number of the session (Session Id). In JSP pages, a session object
is an implicit object, which can be accessed in servlet by request. In the Servlet, it is
invoked by method getSession() with the following Java code:

HttpSession session = request.getSession();

The request is necessary to obtain a reference to an object of HttpSession type. The
method getSession() returns an HttpSession type. Then, the Servlet identifies the client
(the browser), if an HttpSession Object is already instantiated, it is used, otherwise a new
session object is created. This behavior allows the maintenance of the state in application
pages (it is not possible for simple request!).
The three standard methods used to work with attributes of a session object are the
following ones:
public void setAttribute (String name, Object value): it sets an object in session
with a name;
public Object getAttribute (String name): it gets an object from session with a
name;
public void removeAttribute (String name): it removes an object in session with a
name.

Now, we shall fill the project beans and set them in session, before saving them in the
DB. Proceed to walk. So, step by step, we shall manage the company bean, and set it in
session before dispatching it to the JSP page (controller and view in MVC pattern).
The company jsp page is initially empty. Then, after submitting the form, the saved
bean in session (CompanyBean.java) is returned to and processed by the JSP, which fills
values in the form fields. We shall see the filled in form and can go to the employee page.

First, change the bean CompanyBean.java, adding the list of employees
(companyEmployees ArrayList)!

Figure 101. ArrayList companyEmployees.

Then, change the jsp name in formCompanyFull.jsp: it will use the session.
As soon as we arrive at the page of the company, for the first time, the boolean variable
(companyFilled) is not used, since in the session object COMPANY is empty, so we can
not see the link to the employee JSP page. The companyid field is also empty! We can
digit this field!

Figure 102. Browser, empty formCompanyFull.jsp.

If the session is not null, the bean fields are taken from the session bean and set into JSP
variables, which dynamically pre-populate form elements with the data originally entered
in the form by the user, using the following java code (for example, for to the idcompany
field).

Fof idcompany variable:

String idcompany=;

Bean:

CompanyBean company = new CompanyBean();

Test of session:

if (request.getSession()!=null &&
request.getSession().getAttribute(COMPANY)!=null){

idcompany is filled in by the bean value:



idcompany = company.getIdcompany();

Input idcompany value of the JSP page:



<input name=idcompany value=<%=idcompany %> type=text
maxlength=11>

The idcompany field will be also used to enhance the hidden field of
formEmployeeFull.jsp.

The following screenshot shows the formCompanyFull.jsp JSP.

Figure 103. formCompanyFull.jsp and use of session.


Below you can see the changes made to links and input fields.

Figure 104. formCompanyFull.jsp changed links and input fields.

Now we shall populate the form input fields and submit the form of the
formCompanyFull.jsp JSP page!
After populated and submitted the company form, in the Servlet, the company bean is
populated (with sets) and is put in the session with the attribute COMPANY. The
Servlet manages the fields, and dispatches to the formCompanyFull.jsp JSP page.

Figure 105. Servlet, company bean and session.

Now, we can note that the Company ID (idcompany) field is no longer editable (key
field con Company and foreign key for Employee).
It is possible also to note the activation of the employee link!

Figure 106. formCompanyFull.jsp, pre-populated form.

Now just connect the employees to the company!


After populated the company form, click on Insert Employee link and populate the
employee form!

Figure 107. Browser, empty formEmployeeFull.jsp.

We need to set the company foreign key of the employee. We can choose to:
use a Request variable (from company JSP to employee JSP through Servlet),
which fill in the hidden field of employee JSP;
use a Session variable (from company JSP to employee JSP through Servlet),
which fill in the hidden field of employee JSP;
use the company Session bean (already set in session through Servlet), which fill
in the hidden field of employee JSP;
use no hidden field for employee, and set the foreign key only in Servlet.

Now, we shall use the companyid field of the company Session bean!
By clicking on the button Insert Employee, we get to the page of the employee, also
managed by the sessions, as we can show in the following screenshot.

Figure 108. JSP - formEmployeeFull.jsp.

We shall manage the employeeid field as the companyid field.

Figure 109. employeeid field formEmployeeFull.jsp.

The same thing for other employee fields.



Figure 110. formEmployeeFull.jsp changed input fields.

After populated and submitted the employee form, the idemployee field is no longer
modifiable and the link appears for the insertion of a further employee.

Figure 111. formCompanyFull.jsp - links.

Finally, we shall manage the servlet side linking the company to the employee (using
the command whatsend) with GET method. If we decide to enter an additional employee,
the Servlet removes the attribute EMPLOYEE from session.

Figure 112. Servlet, link GET.

If we click on Insert Another Employee, we view the same empty page again, we can
insert and save a new employee: this operation lead to the increase of the employees
arraylist associated with the company.
We must modify the servlet Java code to increment employees ArrayList, as shown
below.
Figure 113. Servlet, employees ArrayList.

Now the company object (with its employees) is ready to be stored on the just created
database.
Now try to insert an additional employee!

Figure 114. Browser, additional employee.

If we want to see employees, we can use a for each loop that displays the employees
to console.

Figure 115. Servlet, employees arraylist on console.

We shall click on home page to remove session objects: in this way, we return to the
jsp corresponding to the insertion of a new empty company. The Servlet java code is
shown below.

Figure 116. Servlet, how to remove session objects.


7.5. Connection to MySQL DataBase, Commit and Roll-Back
It is four oclock!
Now we have the object company with its employees.
Let us save to the DataBase!
The following paragraph illustrates a very simple method of saving!

The first thing to do is download the Java Connector to DB at the URL
http://dev.mysql.com/downloads/connector/, which contains a list of connectors to work
with different programming languages. Now, simply download the library for independent
platform!
This library can be move from the windows environment of development in any testing
or delivery/ operation /distribution environment (also Unix-like).
We shall extract from the zip library the mysql-connector-java-5.1.34-bin.jar file and
save it in the lib folder created within the project.
We can put in one of two JSP pages (company o employee) a button Save Company on
DB, which suggests the user the possibility to store and persist data on DB.

We need to create the DAO (Data Access Objects) class, named SaveMySQL.java, to
manage the CRUD with the database.
Initially, we shall manage the connection with the DB:

private static final String DB_DRIVER = com.mysql.jdbc.Driver;
private static final String DB_CONNECTION = jdbc:mysql://localhost:3306/gestione_imprese;
private static final String DB_USER = root;
private static final String DB_PASSWORD = root;


The driver is related to the Java Connector. The other parameters specify the host
credentials to access DataBase.
Within a try considering the SQLException error in the DB, we are now connected to
the DB:

conn = getDBConnection();


Then set AutoCommit to false (so, we shall set when commit!):

conn.setAutoCommit(false);

This setting allows the final commit, only if all operations were successful.

conn.commit();


If any transaction does not go well, it will be made a rollback with error (which in this
case is returned to the Servlet, using the element throw):

conn.rollback();
System.out.println (INSERT ERROR:Transaction is being rolled back);
throw new SQLException(sqle.getErrorCode()+:+sqle.getMessage());


Now, it is possible to create the insert SQL script for the company:

String insertCompany = INSERT INTO COMPANY
(idcompany,company__name,phone,email,date_ins) ;
insertCompany += VALUES (
+ company.getIdcompany () + ,
+ company.getCompany_name + ,
+ company.getPhone () + ,
+ company.getEmail() + ,
+ SYSDATE());
System.out.println (INSERT QUERY:+ insertCompany);
int resultInsertCompany = stmt.executeUpdate(insertCompany);
System.out.println (resultInsertCompany: + resultInsertCompany);


We can use a simple log-like with the System.out.println command, which write on
console.
Then, it is possible create the insert SQL script for the employees (if present):

ArrayList<EmployeeBean> employees = company.getCompanyEmployees();
for (EmployeeBean employee:employees)
{
String insertEmployee = INSERT INTO EMPLOYEE
(idemployee,surname,name,badge,FK_company,date_ins) ;
insertEmployee += VALUES (
+ employee.getIdemployee() + ,
+ employee.getSurname() + ,
+ employee.getName() + ,
+ employee.getBadge() + ,
+ employee.getFk_company() + ,
+ SYSDATE());
System.out.println(INSERT EMPLOYEE:+insertEmployee);
int resultInsertEmployee = stmt.executeUpdate(insertEmployee);
System.out.println(result Insert QUERY:: +resultInsertEmployee);
}


In this case, employees are gotten from the company bean and cycled in a for-each loop.
At the end, the connection is closed:

finally {
if (stmt != null ) stmt.close();
if (conn != null ) conn.close();
}


The following screenshot shows the java code.
The Connection String.

Figure 117. DAO SaveMySQL.java Connection String.

The Connection Method.



Figure 118. DAO SaveMySQL.java Connection method.

The Insert Method.


Figure 119. DAO SaveMySQL.java insert method.

The Search Method.



Figure 120. DAO SaveMySQL.java search method.

We have to change the Servlet for saving data on the DB (SaveMySQL.java) and then
dispatching to the search page.
Figure 121. Servlet for saving on DataBase.

We can see the console the commit on the DataBase.

Figure 122. Eclipse, console for saving on DB.

We can see the saved companies on the listCompany.jsp.


Figure 123. listCompany.jsp

Figure 124. Browser - listCompany.jsp page.

Now, we shall see also the DB, and check the inclusion of the company and employees
into the DB.

Figure 125. MySQL Company DB.

Figure 126. MySQL Employee DB.


7.6. Examples of error handling in java Web Application
It is about five thirty!
In this paragraph, we shall try to manage the errors with the Servlet. First, we shall
generate a simple error, changing the company insert query. Change the name of a field:
company_name in companyname! The query can not be execute, because a field is
incorrect.
In the next screenshot, we can see how the error is catched.
The stacktrace (on console) helps us to see the errors.

Figure 127. DAO error management.

Where in the class SaveMySQL:



Company_management.db.SaveMySQL INSERT QUERY:

INSERT INTO COMPANY (idcompany, companyname,phone,email,date_ins)


VALUES (23412341234,Manelli,+3923423423,moderninformatics75@gmail.com, SYSDATE())


We can see the ERROR:

Row 55 of SaveMySQL.java (SQLException):
INSERT ERROR: Transaction is being rolled back

We can see how the class leave the error management to the Servlet (throw):

Row 58 of SaveMySQL.java:
throw new SQLException(sqle.getErrorCode()+:+sqle.getMessage());

Console Log of SaveMySQL.class:
ERROR:0:1054:Unknown column companyname in field list


Row 210 of CompanyManagemet.java:
System.out.println(ERROR:+e.getErrorCode()+:+e.getMessage());

Figure 128. Servlet error management.

The error of SQLException type is catched in the block of competence and, in the
DAO class the operation is rolled back. In such a case it can be sufficient an elementary
manage of the error with a simple jsp. The servlet redirects, in case of error, the request on
an error page. We shall create a boolean variable inside the catch: according to this
variable value, we can display the error page or continue with the execution of the servlet.
Figure 129. Boolean variable in Servlet error management.

In the following screenshot, we can see the simple error.jsp JSP page.

Figure 130. Error JSP.


8. Web Application ready for the distribution on Tomcat
It is about six thirty!
We have just finished the project!
Now, we shall to deploy our project on a server in a distribution/ operation /delivery
environment, in fact if we want to use the software we do not need Eclipse!
Click the right mouse button on the project, then Export, then war file.

Figure 131. Eclipse, how to export a war file.

A name is given to the project and then exported the war.


Figure 132. Eclipse, war file generation.

If we open the zipped file, we can see the company_management folder tree project.
In the WEB-INF folder, there is the classes folder with compiled java files (.class). We
shall insert the war project under the server, Tomcat 8, in the webapps folder (C:\apache-
tomcat-8.0.14\webapps).
Tomcat starts from the bin folder (C:\apache-tomcat-8.0.14\bin):
startup.bat/shutdown.bat under Windows environment.
Figure 133. Tomcat bin folder.

Attention! Set the JAVA_HOME Tomcat in the catalina.bat file, indicating the JDK used
for application development. We shall add the line:

set JAVA_HOME=C:\Program Files\Java\jdk1.8_065


The Tomcat startup opens a DOS window.

Figure 134. Tomcat DOS window.

Finally, you can see that the web application will be unzipped in the webapps folder
(C:\apache-tomcat-8.0.14\webapps).
Figure 135. Tomcat webapps folder.

The URL is:


http://localhost:8080/company_management/formCompanyFull.jsp
9. Conclusion
It is about seven! We have definitely finished, so please do not worry!
It has been a good experience working with you!

We have just created and distributed our first web application (not so far from real
professional applications!). It consists of 4 JSP (formCompanyFull.jsp,
formEmployeeFull.jsp, error.jsp, listCompany.jsp); 1 access class to the DB
(SaveMySQL.java); 2 bean class (CompanyBean.java and EmployeeBean.java); 1 servlet
(CompanyManagementServlet).
Simple, isnt it?
I hope this dissertation has been helpful and usefulI look forward to your feedback!
10. Bibliography
Luciano Manelli, Programmazione per il Web, Italian Edition - Publisher ARACNE,
2015.
11. Index of Figures
Figure 1. MySQL Server Installation.
Figure 2. MySQL Server Installation, licence.
Figure 3. MySQL Server Installation setup type.
Figure 4. MySQL Server Installation - Installation.
Figure 5. MySQL Server Installation installed.
Figure 6. MySQL Server Installation configuration.
Figure 7. MySQL Server Installation password setting.
Figure 8. MySQL Server Installation Windows Service.
Figure 9. MySQL Server Installation Server configuration.
Figure 10. MySQL Server Installation test server connection.
Figure 11. MySQL Server Installation last steps.
Figure 12. MySQL Server Installation end.
Figure 13. MySQL Workbench Installation.
Figure 14. MySQL Workbench Installation - setup.
Figure 15. MySQL Workbench Installation - installation.
Figure 16. MySQL Workbench Installation - end.
Figure 17. Workbench environment.
Figure 18. Connection to the Server using the Workbench.
Figure 19. Parameters for connection.
Figure 20. Connection to the Server password setting.
Figure 21. Workbench environment.
Figure 22. Workbench, how to create a new Schema.
Figure 23. Workbench, how to create a new Schema creation script execution.
Figure 24. Workbench, how to create a table.
Figure 25. Workbench, Table name e field insertion.
Figure 26. Workbench, how to create a Table creation script execution.
Figure 27. Workbench, how to modify a Table.
Figure 28. Workbench, how to analyze a Table (query).
Figure 29. Workbench, company table.
Figure 30. Workbench, employee table.
Figure 31. Workbench, how to define a foreign key.
Figure 32. Workbench, definition of foreign key.
Figure 33. Workbench, how to create a Foreign Key creation script execution.
Figure 34. Workbench, how to export a creation schema script.
Figure 35. Workbench, how to export a creation table script.
Figure 36. Workbench, reverse engineer.
Figure 37. Workbench, reverse engineer: connection to the DB.
Figure 38. Workbench, reverse engineer: user/password.
Figure 39. Workbench, reverse engineer: script execution.
Figure 40. Workbench, tables schema of reverse engineering.
Figure 41. Workbench, Workbench, tables schema of reverse engineering with indexes.
Figure 42. Eclipse, files in the extracted folder eclipse Mars.
Figure 43. Eclipse, workspace.
Figure 44. Eclipse, initial screen.
Figure 45. JDK Download.
Figure 46. Eclipse, JDK configuration.
Figure 47. Eclipse, new server configuration.
Figure 48. Eclipse, Tomcat selection.
Figure 49. Eclipse, Tomcat server and installed JRE.
Figure 50. Eclipse, another way to configure a server in Eclipse.
Figure 51. Eclipse, how to start the selected server.
Figure 52. Eclipse, how to create a web project.
Figure 53. Eclipse, configuration of a web project.
Figure 54. Eclipse, configuration of src e classes folder for a web project.
Figure 55. Eclipse, context root and context directory configuration.
Figure 56. Eclipse, created web project.
Figure 57. Eclipse, how to create a JSP.
Figure 58. Eclipse, JSP configuration.
Figure 59. Eclipse, JSP script.
Figure 60. Eclipse, how to modify a JSP script.
Figure 61. Eclipse, how to run the server.
Figure 62. Eclipse, started server.
Figure 63. Eclipse, run from menu.
Figure 64. Eclipse, run from play button of menu.
Figure 65. Eclipse, Run from project.
Figure 66. Eclipse, selection of the server.
Figure 67. Eclipse, web application configuration on the server.
Figure 68. Eclipse, hello.jsp web page.
Figure 69. Chrome, hello.jsp web page.
Figure 70. Eclipse, welcome file list.
Figure 71. Eclipse, how to create a Servlet.
Figure 72. Eclipse, servlet name and package configuration.
Figure 73. Eclipse, servlet methods definitions.
Figure 74. Eclipse, Servlet script.
Figure 75. Eclipse, how to create a class.
Figure 76. Eclipse, class name e package configuration.
Figure 77. Eclipse, Class script.
Figure 78. Eclipse, how to create a JSP for our web application.
Figure 79. Eclipse, name of JSP.
Figure 80. Eclipse, form JSP Java code.
Figure 81. Browser Chrome, form.
Figure 82. Eclipse, doGet and doPost in a Servlet.
Figure 83. Eclipse, POST result on the Eclipse browser and on the browser.
Figure 84. Eclipse, GET result on the Eclipse browser and on the browser.
Figure 85. Eclipse, form companyForm.jsp.
Figure 86. Browser, empty form companyForm.jsp.
Figure 87. Browser, filled in form companyForm.jsp.
Figure 88. Eclipse, form employeeForm.jsp.
Figure 89. Browser, empty form employeeForm.jsp.
Figure 90. Servlet CompanyManagement.java and console.
Figure 91. JavaBean class creation.
Figure 92. JavaBean Version ID creation.
Figure 93. JavaBean Version ID created.
Figure 94. How to Generate Bean Getters and Setters step 1.
Figure 95. How to Generate Bean Getters and Setters step 2.
Figure 96. Eclispe, CompanyBean.java.
Figure 97. Eclispe, EmployeeBean.java.
Figure 98. JSP links companyForm.jsp.
Figure 99. JSP links - employeeForm.jsp.
Figure 100. JSP links homepage.jsp.
Figure 101. ArrayList companyEmployees.
Figure 102. Browser, empty formCompanyFull.jsp.
Figure 103. formCompanyFull.jsp and use of session.
Figure 104. formCompanyFull.jsp changed links and input fields.
Figure 105. Servlet, company bean and session.
Figure 106. formCompanyFull.jsp, pre-populated form.
Figure 107. Browser, empty formEmployeeFull.jsp.
Figure 108. JSP - formEmployeeFull.jsp.
Figure 109. employeeid field formEmployeeFull.jsp.
Figure 110. formEmployeeFull.jsp changed input fields.
Figure 111. formCompanyFull.jsp - links.
Figure 112. Servlet, link GET.
Figure 113. Servlet, employees ArrayList.
Figure 114. Browser, additional employee.
Figure 115. Servlet, employees arraylist on console.
Figure 116. Servlet, how to remove session objects.
Figure 117. DAO SaveMySQL.java Connection String.
Figure 118. DAO SaveMySQL.java Connection method.
Figure 119. DAO SaveMySQL.java insert method.
Figure 120. DAO SaveMySQL.java search method.
Figure 121. Servlet for saving on DataBase.
Figure 122. Eclipse, console for saving on DB.
Figure 123. listCompany.jsp
Figure 124. Browser - listCompany.jsp page.
Figure 125. MySQL Company DB.
Figure 126. MySQL Employee DB.
Figure 127. DAO error management.
Figure 128. Servlet error management.
Figure 129. Boolean variable in Servlet error management.
Figure 130. Error JSP.
Figure 131. Eclipse, how to export a war file.
Figure 132. Eclipse, war file generation.
Figure 133. Tomcat bin folder.
Figure 134. Tomcat DOS window.
Figure 135. Tomcat webapps folder.