Registration Form in JSP
For creating registration form, you must have a table in the database. You can write the database logic in JSP file, but separating it from the JSP page is better approach. Here, we are going to use DAO, Factory Method, DTO and Singletion design patterns. There are many files:
- index.jsp for getting the values from the user
- User.java, a bean class that have properties and setter and getter methods.
- process.jsp, a jsp file that processes the request and calls the methods
- Provider.java, an interface that contains many constants like DRIVER_CLASS, CONNECTION_URL, USERNAME and PASSWORD
- ConnectionProvider.java, a class that returns an object of Connection. It uses the Singleton and factory method design pattern.
- RegisterDao.java, a DAO class that is responsible to get access to the database
Example of Registration Form in JSP
|In this example, we are using the Oracle10g database to connect with the database. Let's first create the table in the Oracle database:|
We have created the table named user432 here.
We are having only three fields here, to make the concept clear and simplify the flow of the application. You can have other fields also like country, hobby etc. according to your requirement.
This jsp file contains all the incoming values to an object of bean class which is passed as an argument in the register method of the RegisterDao class.
|It is the bean class that have 3 properties uname, uemail and upass with its setter and getter methods.|
This interface contains four constants that can vary from database to database.
This class is responsible to return the object of Connection. Here, driver class is loaded only once and connection object gets memory only once.
This class inserts the values of the bean component into the database.