JSP CRUD Example

In this tutorial you will learn about the JSP CRUD Example and its application with practical example.

JSP CRUD With Pagination

Here we will make an project of CRUD (Create, Read, Update and Delete) with JSP and also we are going to use Pagination in this project. If records are too many so on single page it takes time so it is better to break the page into parts so that loading time of page become reduce, The Pagination do work for this theory.

Table Of Contents

First we need to create a database for CRUD and Pagination. I have XAMPP in my system if you do not have please download it, Also you can use Oracle Database. Follow the steps for creation database.

 

1.step: After starting your XAMPP server open this link in browser http://localhost/phpmyadmin/

7

  1. Create an Database on click of “New”. I have created with name of “EmpManagement”.

8

  1. After successful creation of database now we need to create table, As per my requirement I have created a table with name of “Employees” and number of column is “7”. Check below image.

9

  1. Now we need to enter our columns name and also need to set data type like below image.

10

Now we are all set with database creation. Now we have to create Java Web Project in which we are going to use this Database. Check below steps for this.

 

 

#Create Project: In this step we will create new project with netbeans, click on “File>New Project” You will get screen like below image.

11

#click on “Next” button and then enter your project details like below image.

12

#Again we need to click on “Next” and then we will “Finish”.

13

#iAdd Library: so we are all set with project creation now let’s add some important library in our project ,which we are going to use in our project.

 

#jstl-1.2.jar: Let’s include JSTL(JSP Standard Tag Library) in your project

After downloading jar file, do right click on your project and then go to properties. Like below image.

14

Now go to libraries and then click on Add JAR/Folder Option.

15

 

#Select your jstl-1.2.jar from your directory and after including jar file you will get image like below.

16

#now click on Add Library… option and select MySQL JDBC Driver library and then click on Add Library as i did like below image.

17

#Now you will get screen like below image, simple click on “OK” button and these libraries will be added in your project.

18

Now we are done with including libraries in our project, let’s move to coding side.

Project Structure: Let’s create one by one some jsp and java classes for this project.The project structure will look like below image so please make classes according to this structure.

19

#UserBean.java:Java Bean are classes that encapsulate many objects into a single object. It contains constructor, Getter, Setter Methods. With the help of Setter and Getter method user can set and get data. Check below code.

#UserDAO.java: So this is User Data Access Object, here we will write queries of connection, Creation, Reading, Updating and Deletion and also for Pagination. Check below code.

#header.html: This will be our header which we will include in our jsp pages.

#index.jsp: This will be our launching page, do coding of this as I did, check below code.

 

#adduserForm.jsp: Here we have included userForm.html file , which will redirect to addUser.jsp page after submitting all details.Check below code.

#userForm.html: This is the html file in which we create a form for registration and then it redirect to addUser.jsp. Check below code.

#addUser.jsp: So from here we will add user. From this we have called save method of UserDAO class.

#AddUserSuccess.jsp: After successful registration this code will run.

#errorPage.jsp: If any exception or error occurred so this code will give error message.

#viewUsers.jsp: With the help of this code you can view all data of employees.

#updateForm.jsp: This will be our Update form, here you can update your details.

#UpdateUser.jsp: This code will run when you were done with updation.

#DeleteUser.jsp: If you want to delete any employee so you can delete with this code.

#paginationPage.jsp: So this code will work for pagination.

Download: You can simply download this project by below link.

 

 

#Output: Let’s run this project you will get output like below images.

#Home: This will be our Home Screen.

20

#Add Employee: This screen will appear when you click on “Add Employees” or “Add User”.

21

#AddUserSuccess: After successful registration this screen will appear.

22

#ViewUser: In this screen we can see all employees list.

23

#Edit: When you click on edit the below screen will appear. I have edit salary 12000 to 150000.

24

#After Update: After updation it will look like below image.

25

#Delete: When you click on delete so data will be removed from table, I have deleted user “KK”, So below screen will appear after deletion.

26

#Pagination: see pagination in below images.

27 28 29

 

So this was a simple example of CRUD with Pagination hopefully this will help you.

In this tutorial we have learn about the JSP CRUD Example and its application with practical example. I hope you will like this tutorial.