3 Easy Steps To Create A Simple JSP Login Page With MySQL

MySQL has always been my favorite database because it’s very easy to use. All you have to do is install a local server and get right into it. I recently started experimenting with JSP. For any application, the first thing that I do is build a login page.

Building a login page helps because there’s a database connection involved. You get to know how the data is flowing. What I’ve done is created a simple JSP Login Page with MySQL that will validate the username and password against the database.

You can use any IDE like Netbeans or Eclipse to build a JSP application. I prefer Netbeans over Eclipse.

Before building the application, make sure you have the MySQL Java Connector added to the libraries. Without it, the server (for e.g. Glass Fish Server) will throw an error.

Step 1 : Create The Login Page

Here’s the code for the login page.

Step 2 : Create The Validation Page

Once you have created the login page, the next thing that you need to do is create the validation page. This page will validate the username and password against the MySQL database.

Here’s the code for the validation page.

Step 3 : Build And Run The Application

Once you have finished both your login and validate page, you can run the application in the browser. Note that I have added the ‘required’ keyword in both the fields which means you can’t leave the fields empty.

jsp login page with mysqlIt’s a simple client side validation that prevents the server from additional stress.

3 Areas Where Things Can Go Wrong

1. Adding the MySQL Java Connector

For any application that uses MySQL as a database, make sure you have the API installed. In this case make sure you have added the MySQL Java Connector JAR file.

jsp login page with mysql

Without the JAR, you won’t be able to connect to MySQL even if you’re server is running.

2. Keep The Database Attributes Correct

While coding any database driven application, always make sure that you have coded the correct database attributes for the SQL queries. The same principle applies here as well. Also, make sure the port through which you’re connecting to database is correct. Or, it will cause all kinds of error.

jsp login page with mysql

Always make sure that you have written the correct database name, table name and attributes in the SQL queries. When an application becomes bigger as you go further into it’s development, errors like these are very difficult to debug and take a large amount of time.

3. Server Is Running

This is the most important thing to remember for any web application. Even if everything is complete, if your server is not running, the application will not validate anything.

jsp login page with mysql

If you’re running a local server like the WAMP Server or EasyPHP Dev Server, make sure the server and the services are running.

Author: Lahaul Seth

A programmer and a web developer, he is the founder of Lion Blogger. His main hobbies are web design & development and providing freelance writing services to clients.He works full time as a Senior Systems Engineer at Infosys Ltd.

Share This Post On
  • Vinay

    Thank You Sir

  • D

    Thanks very much. It really helped me with my project. I was trying to solve this problem with my login page for so many days but couldn’t. It works for me.

Pin It on Pinterest

Share This
badge