Registration Form using JSP + Servlet + JDBC + MySQL Database Example

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone in this video we'll create a small web application which has a registration form and we use GSP solar television my sequel technology stack to develop this web application so we'll build a simple employee registration module using JSP so allegedly vision massacre database alright so we'll be using model-view-controller design pattern to develop the sparrow application so before getting you know before developing this we have application I would like to you little bit over you of model your controller design pattern alright so look at here the high level diagram or Model View controller design pattern so once we hit a URL in a web browser so based on the URL it will call the corresponding controller so controller is consists of servlets so servlet will basically process the you know HTTP request and it will write will you know invoking the model data and at the back end we use my sequel database so so database layer so we have one more layer that is a dowel layer so dowel you will query a data from the database and it will store that data model and controller will invoke that model and controller will send that model data to the JSP page and just because again will be rendered on a web browser with the model data so this is the typical flow in a model view controller design pattern so what is the model view controller design pattern so Model View controller design pattern is a pattern used in software engineering to separate application logic from the user interface as the name implies the immune support has three layers so model layer depends the business business layer of the application in the controller layer manages the plot application and the view layer defines the presentation layer of the application so I will show you how these layers works with an example bit later so just to focus what the model layer does I what is the responsibility of control earlier and earlier all right now let's come to the example so we will develop this employ a resistor form through which my can register to the web application all right so look at here the fields first name last name username password address and contact number so I imply when they enter all these fields and once hit the submit button so this request will be so this is the basically HTTP POST request so this request will be handled at a servlet so servlet will handle this HTTP POST request and it will process the you know request parameters and it will create a employ object using model layer and we will forward that model data khuda gawah layer and bowel you will have a connection with the Massaquoi database and it will store the data into my secure database so we will see this in example so let's have a look into the tools and technologies that we will be using so we'll use you know we'll use GSB and we use Eclipse IDE to develop this application and we use jdk 1.8 or later and we'll be using apache tomcat yet fine for you and we use gstl and server at EPA alright and we also use my sequel JDBC character to know to connect to the my super database using JDBC API so let's have a look into the development steps so this is a very useful section because it outlines what we are going to implement in this video tutorial so first we create a Eclipse dynamic web project next we add all the dependencies next we create project structure next we create them or we set up the MySQL database and next we create a Java bin that is I imply next we create a employ Dao class next to create a temper servlet and next we create a employ register dot JSP page next we can't have quadrakill or J's and finally we have a demo alright so as I mentioned we are using a model your controller design pattern so employee employee bin it acts as a model layer and employed ow it is a doubler Empire servlet it acts as a controller layer and employee register ID employee tells these two GSB pieces are acts as a earlier all right now let's implement these steps one by one so first we need to create a dynamic web project in Eclipse ID so before that we need to set up the database right so here is the DDL script so this is the employee table it has ID first name last name username password Atlas and contact fields alright so we can just copy this DDL script and we can execute in a my sequel workbench so I am in a bicycle work bench so let me create a fresh database so just type create database and give database name here as employees and mute this query so this will hit database and database name is employees all right so look at her employees and underemployed database we create a table so this is the DDL script for employee table we just execute this DDL script just to select the employee database here and you exhibit it yeah here we go we have successfully created my table just refresh here so look at here we have collected I am to our table now our database setup is ready now let's have a look you to the next step so this fourth step we have already done because we need to set up the database before creating the application so now we can create a Eclipse dynamic web project alright so I highly suggest you guys to start coding with me so that we can implement this tutorial together and you will learn you know coding and yeah there is a lot of fun okay so just switch to the Eclipse IDE and let's create a dynamic web project so I am in a Eclipse IDE now in order to create a dynamic web project to go to the file new and choose dynamic web project and here just you project name as there's discretion GSP so that jdbc example okay hit finish now we have created up we have dynamic dynamic web project so look at the I know default project structure here so we have a Content folder we are buying a folder and inside of a pioneer folder we have only product so inside lip odor we add other you know required dependencies that is the jar files and we have contained two basically you know which tour at pages GSP pages and other resources like the GS files I have CSS files okay once we create the project let's have a look into the next step so next step is we need to add all the jar dependencies all right so under the folder let's just add these four dependencies GSP API gstl my sicko connector Java and sublet EPA so don't worry a once will complete this tutorial I will host this was code up this tutorial on the github repository so and probably I will provide a link in a video description so that you can able to download this jar files as well as the whole project ok now we have added all the entire dependencies let's have a look into the next step the next step is we need to create a project structure so right click Anasazi folder new and create a package structure your package name as net dot Java writes dot and this is the registration module so given him as a registration head finish and let's create a few more packages create a model package and let's create a controller package let's create our package alright so as I mentioned earlier we are using model UT Sun pattern right so we have a model layer in place controller layer in place now we create a view layer so just create a folder under web and let's name this folder as views okay so use polar contains no JSP pages so once we have a model layer controller layer and you there in case next let us see the next step so next step is we need to set up the database so this step we have already done and the next step is we need to create a my java bin class so under model package just right click new and class and leave it as employee so inside I employ class let's create private fields first name last name employee a new username password address and contact and right-click and let's create a getter setters right click source get the setter methods yeah here we go so once we create a private fields we need to create a getter setter go through two x's this private field side so once the employee class is in place now let us see the next step so we need to create an employee at our class so right click on now pack egde new and choose class and let's name it as a employ Dao so in this class we basically write a JDBC code to connect to the my sequel database and we store the employee register data into my sequel database so let me quickly write this code here so look at here we have just created a resistor employee method and we are passing here employee object and this is the insert statement inside SQL statement and here we are using try with Rousseau statement and here we are connecting to the my sequel database using JDBC URL and username password it's pretty simple right and here once we got the JDBC connection object then we create a prepare statement and we pass the SQL statement here and look at here the placeholders inside SQL statement and so this is the prepare statement so we can set you know place whatever I use by using this API it's alright and then we execute the purpose statement using execute update method so this method will return an integer that means the number of Records in circuit all right so pretty simple so we basically connect to the my super database using dwrl user and password I indicate the purpose statement object and we execute the professed it without it so it's very simple now how quote no let's have a look it to the next step the employee servlet now let's go let's right click on controller package new and let's create solid and you name it as a my servlet okay now we have created a servlet so what we'll do we'll just configure Apache Tomcat server to the class path of this project so in previous video I have shown you how to configure Apache Tomcat server in Eclipse now go to the project right click here build path configure build path and here click on add variable and no not add variable just click on add library and choose server runtime next and choose this Apogee tomcat 8.5 hit finish now we have added up which drunkard server to the class path of this project hit apply apply and close now you can see soap you up the jar files are required from the apache tomcat a new server to the this application so now you can see the errors are gone here okay now we have a employees are let in place now next void and let's write the logic so we need to handle the HTTP POST request like so here we need to write the code inside the dopost method so so first we will create you know we employed our class object okay and here never see another school and you just get the request parameters stream first name corporate West don't get pattern and you can get first name from the request parameter alright so just copy the statement and paste here just access the last name from the request pattern and copy this and similarly get all the requests Paris so look at the employee class so here we have username password password and we have address at this address contact that's a all right so once we got all the request parameters from request object now we can create an employee employee object okay you just set the employee object with all the data post impersonate look like outlasting my username employee password employee address employ address sorry contact here we go so once we create the apply object then we can call the employed ow method employed dot the resistor employee and then we can pass an object like this here we go all right so once we stood the employee objecting to my Sequoia division we need to redirect right so for that just call the redirect method here Sandra ducked and here you need to pass the GSP pieces so we'll create a Jesper basis and then we add here so top three for time being we just keep empty so later once we create the JSP pages then we can we can do name here okay it's pretty simple so red light so how created more earlier and we have created a control earlier now and we also created a W now it's time to create a wave here right now let's get a JSP pages so I'd click on our views folder new and then choose a CSV file and you GSP page name as I employees you store objects because you to finish now here we need to design the HTML form all right so let me quickly design this HTML form and then I will explain you okay so it's pretty simple so we have HTML form here and this is the action and this is the forced all right and look at here the URL a resistor so we need to map this URL with the servlet so here we need so by default this URL is mapped here now replace this with register so once we hit the submit button then this servlet will be called and that forms formulate I will be handed in this ability okay so look at the method so method is very important we are using post method here so in order to send the formulator we usually use HTTP POST in the third year okay and you look at the fields force name and last name username password address and contact number perfect right so you can see here in our model that is they imply class we have we are using the same number of fields and under GSB also we are using same fields this makes sense right so very simple form and we have created estimate able to render these text fields in a proper permit and finally you have submit button so once we hit the submit button this form data will be you know send to the solid okay so now we have a my register George's page okay so once the data form data will be stored in the my secure database then we need to redirect it to some other page like so for that let's create a one more JSP page right click new and choose a JSP file and just your name as employee details dot JSP we finish and here we just display a success message okay so once the employee resistors display then we can display my successfully register like this so before deploying this application so first I would like to give you some tips here so look at here we have only one sublet what we need to handle it two requests so first we need to handle I employ register dot JSP page so once we hit some link let us say HTTP GET request then this single servlet will handle both I get request as well as well as post request all right so we haven't implemented doget method it lets waiting let's implement it to first so in the doget method we need to create a dispatcher servlet which will move forward the request to the corresponding JSP page okay now look at here we are forwarding I know request to this JSP page okay and one more thing is whenever we saw when we submit the form and this Porto first will be execute in a servlet and here will no need to resend user send a redirect method so we have to use required dispatcher to forward the request to the corresponding in just page so let's use your employee details so once we have them seen some changes let's wait and let's deploy this application and let's see the demo I right click on our server hit finish hopefully this application will deploy successfully let us see if there are any errors or exception on a console no errors no exceptions all right now our application is up and running you know let's let's create a proper URL so open the your favorite browser and just hit this link so make sure that this resistor you should enter this resistor here because it will map this I know HTTP GET request with the servlet and hit enter yeah here we go so I employ a resistor form will be open so let me explain you the flow so this is the HTTP GET request and this will map and servlet here okay and so this is the get method so it will call to get method here and will forward this request to the employ a register dot JSP page and this is the I know employee resistor form so that we have seen in a browser right so this is the employer is so form it will display here and just we fill up the form here first name last name username and password you can enter any password that you want and fill up address and contact name and hit submit yeah here we go the employee data form data has successfully stored in a my sequel database and we have got a successful success web page here let's go and let's verify in my sequel workbench so this is the employee database inside that we have a employed table that we have created previously and let me refresh yeah here we go so we get here the record is inserted in a my sequel work my sequel database table so this is how basically we create we have application which has employed as usual form using JSP select jellivision my sequel alright so I hope you found this video tutorial useful and we have also use a model-view-controller design pattern to you know to structure our web application alright so if you find this tutorial useful then subscribe to our YouTube channel so that way whenever I will publish such videos you will get notified thanks for watching I will see you in the next video
Info
Channel: Java Guides
Views: 330,199
Rating: undefined out of 5
Keywords: jsp, servlet, jdbc, mysql, javaguides, eclipse
Id: DzYyzmP4m5c
Channel Id: undefined
Length: 25min 25sec (1525 seconds)
Published: Thu Jan 16 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.