Simple Login Application using JSP, Servlets and JDBC connectivity to MySQL - Analysis-Design-MySQL-Setup

Article Index

1 1 1 1 1 1 1 1 1 1 Rating 3.60 (66 Votes)

Analysis and Design

The application is pretty straightforward and it is not too hard to design. Looking through the requirement, we need a database instance in MySQL which has a table. We would name this table as USERS.

USERS table needs to have user_name and password field but can have other fields.

For the login screen, we will create a JSP. For the home page after successful login, we will create another JSP. Following MVC, we will let Servlet handle the request. The connectivity with DB should be extracted out of the Servlet for a complex application. However, for simplicity we have maintained it within the servlet.

Below are the identified elements:



Setup the database:

You can create a new database in MySQL or create the below table in an already existing database. Below is the script which you will have to execute in MySQL prompt for create the table.

`first_name` VARCHAR(100) NOT NULL,
`last_name` VARCHAR(100) NOT NULL,
`user_name` VARCHAR(100) NOT NULL,
`password` VARCHAR(100) NOT NULL

You can use the below insert to add users to the USERS table. You can add as many users as you want in this table.

INSERT INTO `users` (`first_name`, `last_name`, `user_name`, `password`) VALUES ('Tech', 'Freaks', 'tech_freaks', 'Passw0rd');

For Connecting to MySQL database from Servlet, you would require MySQL JDBC drivers. Below is the link to download the latest and greatest version of the drivers.
MySQL Driver :

Once we have this we are good to start the Java side development. Below screen explains how the directory structure will look in your development environment.

Application Directory Structure

Joomla SEO by MijoSEF