Transcripts
1. Introduction: Hi guys, welcome to the course. Learn GSP. So I'm Priyanka, your
instructor for this course. A little bit
background of myself. I have experience in full
stack web development. I'm also an AI and ML enthusiast and have done numerous
projects in it. I also have experience in online teaching and I'm
also an author at medium. So what do we get to learn
in this course? Learn soap. Let's JSP difference between, so let's and JASP JDBC, different types of
redaction which we can do some projects and much more. So without further ado, let's get started and I wish you good luck
and happy learning.
2. Introduction to Servlets: Hey guys, welcome
back to the course. So let's learn what are solids. So, so let's, uh,
basically Java programs that run on web applications. So they basically act
as a middle layer between the requests which
come from the web browser, that is, as users, whatever requests we
sent to the website. And it also interacts with the databases and
the client as well. Okay? So server actually
works as a middleman. And whatever requests we
get from the web browser, which things are sense? Session said. It interacts with the
databases and gives back the response to the web
browser or the users. Okay, let us understand
how it is done. So what we'll do is I
will open paint and show you how it actually works. So first of all, it will have a browser. So suppose this is our client browser. Let's remove this. I will simply write it. I think this one I can use. That was a right angle triangle. Okay? So this is the PC
we generally use. For your convenience,
I will write it as. This is the client uses the spin veto web browser. The web browser, we will
connect to the server. So let this be the server. This is the survey, and we will be sending some
request to the server. So inside this over, we will have the
JSP or the Soviets. Okay? So we will have JSP. Well, so these fees are actually like it
is converted to job. So let's we actually
write in Java when GSP, so it's basically steamer based, then it is converted to Java. And from there, we can
perform the other tasks. So now we'll get some requests. So this is a request
that is coming. Change the color. So this is a request me write. Requests can be anything
like if we want to access some part
of the website or you want to login or whatever data you
want from the server. So this is a kind of way. Okay? Now, next thing is, once the request comes to here, then it actually processes the request list. Processing. That's done here in the server with the
help of the servlets. And then if there is any
database color something, then the database
is also called. So I'll quickly create a database here. Okay? So this is our DB DW. So this is a database and if any coal is declared
to the database also, then it will call the database. And it will also get a response
back from the database. Comes to the database and
on so goes out from that, determines the quiz comes to the database and also from three to
visit fit to some data. And then after the
request processing, it will give back the
response in the form of HTML or the beach. This the response and it is given back to the web browser. Okay, so let's recap. The user sends a request via the web browser to the website, that is the server where
the Latin days visa hosted. And then the request
processing happens. And if there is a
database called, then that is also done, all the processor done, and then they send back a
response to the client. This is the overall lake, how this particular servlets
work in terms of how the requests are coming and how they process it and
send back the request. Thank you for
watching this video. See you in next lesson.
3. Install Required IDE: Hey guys, welcome
back to the course. So in this video, we'll be installing the
Eclipse software into our PC. So for that, go to your web browser and
search for download. Eclipse will be, will be using Eclipse
ID for our development. Now, select the first one. You can see what the package
is and what it contains. Now, you can go and
click on Download. It will take some white. Once it is downloaded, click on the fine. It's time to install it. So you need to select
the second one, which is Eclipse IDE for Enterprise Java and
web developers. This is the one you
need to select. It will provide the tools for developers working with
Java and web applications. So since we will be dealing
with web applications here, and so let's, so we'll
be selecting this one. Okay? Now click on and stone, except wait until it
is getting installed. It will just take some white. So you can give any location
on your laptop or PC. For me, it's C Program
Files, Java, JDK. And this is the floor. This floor, the Java and
this is for the Eclipse. Eclipse is going to be
installed and see you those. And in this eclipse
folder and the JDK, which will be used in Eclipse, well, we stored in
c program file. So these are the two paths. So if you wish, you can change it, but I would recommend
to keep it as it is because this is
what is by default. So you can see like create Start menu entry and create
deck stuff shortcut. This shortcut will
help us to launch the cleft from a deck step
so you can keep it checked. Otherwise, we'll have to every time search it from
the deck step. But whenever we want to see it. If you already have Eclipse
installed in your laptop, then no need to
follow the steps. You can directly hop
into the lessons. But if you do not have Eclipse
installed in your laptop, then you can surely take
this video as a guide, which will help you
to show you how you can install Eclipse
in your laptop.
4. First Servlet Demo: Hi guys, welcome
back to the course. So in this video we'll be
creating our first servlet. So for that, go to
your Eclipse editor. Now, you need to create a
workspace for you to work. So click on Browse
and go do a Dexter. Now create a folder here. Name it My Workspace. You can give any
name of your choice and then click on Select Folder. Now this is going to
be the workspace. Now click on Launch. On your deck stuff. You can see this. My workspace is created
where all the files, which will be creating an
eclipse that will be stored. Now we have this very compete, I'll just close this. Okay, so now we can create
our first program for that. Go to File, click on New, and then click on
dynamic web project. So you need to give
your project a name. So give it a name. I'm going to name it first. So let, for convenience, I will mark this as, I'll give it a number. So suppose 101. So this will help us to track like how many
examples we're trying out. This will be 101, the next
one I do will be 102. So that way we can do it. So next, we are using
this workspace, my workspace to
store this program. And let's go for it. You can keep it as it is, and click on Next. And then again next. So this is your contextual and this is the
content directory. Everything is fine.
Just click on Finish. You have created your web map. So if you go inside Java
resources and you will see a folder SRC slash slash Java. So here we will be
having our Java phase. So here I will simply
right-click New. We'll be creating a soft light which will be running
on our server. So when you just do right-click
and then click on solid. This is going to create
a subnet for us. I'm going to let
inside a package. So I will name it
S com dot subnet. Okay, So this should
be our package. The name of the class
should be first. Okay? So this is the
name of the class. This is the superclass
as we have selected. So let's, so it will be
extending this Java x dot. So let HTTP and HTTP. So, okay, now click on Next. This will be our URL mapping. So when we go to this URL, we can see our output. I'll show you that. And then click on Next. So these are like the default methods which
will be created for you. But for now, I'll just untick do post and I'll
just go with do gate. Now, click on Finish. You could also remove
the default constructor, does not need it. Okay? So this is also valid. Let us understand one by one. You can see this edited, so let and then slash so let. So this is basically
a notation which we will learn in our
upcoming videos that what is a notation
and what it is used for. So for now you can
understand this is a notation which is used to declare that this is
a solid and this is the URL which is
mapped to the solid. Now, the name of our
class as far as sublet, it is extending this
HTTP servlet class. Now, next thing is you're
this or do GET method. So this is a default method. So there are two
parameters or arguments. This method is accepting. When it's this request and the response request is the HTTP request
we're talking about. Response will be, our HTTP
response will be using this. It will also get a fair
idea of this elements. So it is throwing this
exception IOException. Okay? No response to get rider dot append to this
sponsored get rider is basically used for printing
something on the screen. See that I will just remove the default texts and all this to make the code more team. Now, you can see the
red marks of edits. So we need to first
resolve these edits. So how can we resolve
this hitters? This arrows will be
resolved once we have those server in our system. So we need to have
the Apache server. So what you need to do for that, you need to go to your
Chrome or any browser. And then search for download. Apache Tomcat. Okay. If you click here, we're going to download the
version name of Tomcat. So you can see Dom get
nine from the left menu. We can find that. And if you scroll down, you can have all these references
and Tomcat user guide, etc, which you can go
to if you wish to. Quickly click on back. To download the Tom, Good night. You can come here to
the download section and click on Tomcat name. This is for download and this
is what the documentation. So click on Tomcat night. If you scroll down, you can see different
options for downloading. So I will go with
this 64-bit Windows. You can go as far your
configuration of windows. Once it is downloaded, it will be a zipped file. You need to go to the folder
and you need to unzip it. So I will quickly. So this is our Apache Tomcat nine inside this will
have different folders. So we need to import
this in our code. So how can we do that? So now we have downloaded
our Tomcat server. Now how can we
resolve this issue? So for that, you can
go to the syllabus. You can see no, so
what is available? So you can simply
right-click new server. Okay, now we're going
to choose a patchy. And if you remember, we downloaded version nine. So this is Apache Tomcat nine. So we're going to choose
Tom get nine from here. This is the host name localhost. Now go to next, this autumn getName, the train. Now we need to choose the
installation directory. So go to browse and
go to your downloads. Here you have the Apache Tomcat. Now select this file and
click on Select Folder. You have it here.
Now click on Next. And Finish. We have here. Now, how can we configure
this in our project? So go to your
project, right-click. And you can go to Properties. Search for project facets. Project facets. Click here. Okay, So you have
different project facets. I'm in the Java version
and everything. Now go to runtimes. Click on this Apache Tomcat nine and just simply
click on apply. What we're doing is we're
selecting the runtime for this particular
web application. So as soon as you
apply you can see there are no red
dots anymore here. All are gone. So that's a good sign. Now click on Apply and Close. And you can see all the adders which were earlier present. There are a lot of corn. Now, in order to verify, you can go to this libraries and you can see Server runtime. So if you see this over
and time configured here, then you're going
to understand that the service is
already configured. And if not, then you can go to the project facets and
configure it from there. So although errors are gone, now we're simply going to write
hello world program here. So what we'll do is
I'll simply remove this and they print LN. So as I told you, this is sponsored
get writer will help us write something
on the screen. Here you can write H1. So here you can also use HTML
tags to write your code. So that's not an issue. Hello World. Okay. This looks good. This print element help
us do this on the screen. Simply save this. Now let's see how
you can run it. So for running it, you
need to go to your sublet, right-click on it and
go to Run S, ran on. So okay, so select
your local solar. It is Tompkin
version nine for us. Click on Next. You can see this is configured. So if it is in the availability to move
it, to configure it. So only if it is present in
configured, then you can. But I'm this. Okay, So click on Finish. Okay. So what happened? We
run this program and now we see not found.
What is the issue? The issue is, here we
have slash for select. Can you see slash force over it? You can only see the theme of the project 101 plus O blood, but this particular servlet
is mapped to this URL. So we need to go to
this URL to run it. So I'll quickly copy this. Come here in the browser. I think it was in inch. And now quickly close this
here and now paste it here. So this is our local
host port 8081014. So blood, and now you can
see Hello World here. Okay. Whatever we had written
it showing up here. So if you expand tom getName, so you can see this for
servlet is running it now. What if we do not want
this was like to be there. We just want this slash. Remove the first subnet
and save this. Okay? So once you save or make any
changes to your program, you need to again, then it on the server, on Next, Finish and restart. Okay? So now what you can see, even if we do not write
this first servlet here, it's still showing
us this hello world. Okay? Because we have mapped
our URL in such a way, we have just given slash. So that is why even if
we do not give first, we can see this HelloWorld. In this way you can print anything on the screen
with the help of the subnet. So I hope you have learned the basic
concept of a servlet. In the upcoming videos,
we will learn more. So stay tuned to the
course. Thank you.
5. First JSP Demo: Hey guys, welcome
back to the course. So now we know how we
can create our servlet. So let's go back to
our Eclipse editor. Now. Next we will learn
how to create a JSP fight. For that we'll be
creating a new project. So click on new
dynamic web project. Give your project a name. So earlier we created
this 101 leg. This time we'll
create 102 first JSP. Okay? The rest of
it will be same, the workspace will be same. Now, click on Next, then at the next. Okay, So you can see the root
context here and directory. Now, click, you will need to check
this generate web dot XML. So this will be our
deployment district. So I'll tell you exactly
why you're taking this. Let's go ahead for now. Click on Finish. Okay? So we have this first JSP. If you expand it,
liquid close this one. Give them works basically. Ok. Now if you navigate
to the SRC folder, if you open it,
then we have mean. Then we have Java. Then
we have this web app. Inside this way by nF, we have this web dot xml
and this manifest.yml. So if I expand this
for sublet 101, there also we had the
similar SIC, fine. If I open it, we have main. Then Java. See here the java is empty because we have not
written any code yet. But since we have written
out First of lead, here, we have C, Java and then come. So let's if you remember conduits of lead
was off package, then come so let, and then our first servlet
or Java in the web app, if I similarly expand. So you cannot see this web
dot xml because we had not checked that option in our previous project
when creating it. Now, if I collapse this
and let's look into this. So let's understand
this web dot xml. Now. This isn't a design view. I'll go to the source you, okay. Here. You can see there is a welcome file list and we
can see a welcome file, index.html, index.js be
default dot HTML, etc. So here's a list of the
files which will help the server while this
particular project is deployed to the server, it will refer to
this web dot xml. And here as a welcome file. Welcome file refers to the first launched file that
we'll see in the browser, like we have in C. This is the, this
is our first page when we launched this. Similarly, when we launched
the silhouette this way, for these elements, whether
these elements are present, if yes, then it will open it. The name of our project. So this is all, and here actually the
solver will refer to this welcome files and if it is present here,
and then we'll open it. So do we have this index.html
or index or JASP it? No, If not, then we'll
create one. Okay? So you will need to create
this inside this web app. Or you can simply come to the heading of the
project and click on New. When you click on New,
you will get some options here you can see JSP files. So click on that. This will clear JSP file for us. Here. You need to give a
name to your JASP file. So as I mentioned to you that this will
be our launching file. So I will name it
as index dot js, P, index dot js. So this will be our fight. Okay? Now click on Next. All right, finish. Okay. So if you see it is inside
this web app folder. So you could have
directly come to this web app folder and I click on new and
selected JSP file. You can also do it from here, from that project header. Okay. So this is
our index.js file. Let's go to that. Okay. Now we can again see some areas
will resolve that first, let us understand the pH. So we have the language
which is Java JSP page. And you can see this
HTML structure. So inside this, we can write our HTML code as well
as our Java code. Now why we are
getting this error? It's saying that this was
not found in the Java API. So let was not found
on the belt path. Quickly dissolve
this for resolving. Let's go to the belt path. Okay, everything is fine. I think we are already
using this Java 17. So what we'll do is we'll
go to our Chrome and download Java, likes jar, right? Okay. Okey, not here. I think we can do it from here. So click on this job, right? So let me know. Once you have it downloaded, you can show in folder and
its extract all the files. Okay, so we have it extracted. Now go back to your workspace. Right-click on your project. Go to, but it's configurable
Pat, comforted libraries. Now, click on the module path and select, Add External jars. Now go to downloads. You have the jar file here. Open it and you need to select
this executable jar file. So select that and open it. Gonna play after deck,
Apply and Close. Now once you apply and close, wait for some time and
the error will be gone. If not, then you need
to restart your eclipse so you can go to File
and click on restart, and then you can see
that it is gone. So the downloading
and importing of the jar file will help
you resolve this issue. Okay, So now we do
not have any errors, so we can go ahead and
edit this JSP file. Right, welcome here. And here. In the body section, I will again write hello world. I'll use the H1 tags. Save this. And that's all. We can try
to run this on our server. So right-click on your project, then S, then un-solo. Click on this Tomcat. Next. Now you can see there are two projects which
are configured here. When a to select
the only one that will be running on the server. So I'll just remove the
first 1101 for silver it, I will move it to this
available 102 first JASP, I want to run it, keep it in the configured section and I
will just click on Finish. It will restart the server. So again, you can
see Hello World. This time they worry less local
host, 808102, first JASP. So if we go to this one, the previous one, it
was localized to 101. But this is our local host, 80 to answer to first-year
expenses, our HelloWorld. And this is the
title of the page. Okay? So in a similar manner, you can edit this
particular file in here. You can write some p tags. This is website,
something like that. Okay, now save this. Another way to run.
I'll show you. So you can go to this web
app and index.js petal. So one way is from here, we can right-click run Solver. The other way is from here, from the index.js,
we can right-click, then run ads for an unsold. So from here, we
can directly deploy this JSP file to our silver. Now click on the Solver, and this is all
configured project 102 first JASP, click on Finish. And now you can see Hello World. This is a test website. So whatever changes we're making to our code, it's
reflecting here. So I hope now you know
how to create a JSP file in your workspace and
then you can run it. You can manipulate it. You can do whatever you wish
to in order to learn JSP. Thank you for
watching this lesson. See you in the next lesson.
6. Servlet VS JSP: Hey guys, welcome
back to the course. So in this video, we'll
look into the difference between lead and JSP. Okay? So sublet is
basically Java based. Okay? So servlet is Java JSP. In JASP we have, we can have HTML content and also we can use certain script. Let's add a Java code as well. But GSP is mainly based on HTML. I would write JSP based on HTML or
client site maps. So next, we will look into it. The next difference is, so great, is much faster. But GSP is much
slower than silver. Why is it so? Because she has just shared the reason
with you because in JASP, JSP is first
converted into Java. Okay? That is why the process is little slower lake the runtime of JSP will be slower than that. So let me just holiday Java. So since JSP is
converted to Java, it is a bit slower. Since the second difference, we look into the
third difference. That is, if you understand
MVC architecture, which is model view
controller architecture, In MVC architecture, it
will be like a controller. What does controller?
Controller actually takes all the logic, business logic, and
it puts it together. And it also controls the views. Actually basically works as a middleman between the
views and the models. And it runs the business logic. But if you take the JSP, then in MVC architecture, JSP will be the view. So it plays the role
of the view where we actually display the
content to the users. Or it is basically
plays the role of the client site structure. We will have some late as a
controller and James Piazza. So these are some basic
differences between lit and JSP. If I go to the code, you can see if I go
to the first sublet, there are other differences like we can extend the
HTTP server leg here, and this is how the
code is written. And we can also directly write
the HTML code from here. But if we take the JSP example, it will be inside the web app. It will have the
extension dot JSP, and this is how it will look. So I hope you have got an overview of the differences
between net Angie's. Thank you for
watching this video. See you in the next lesson.
7. Web Application Demo: Welcome back to the course. So in the previous video, we learned about JSP
and how we can create a JSP file and write
our code inside it. Now, in this video, we'll be seeing
that how we can use the soul as well as JSP to
write our web application. For that. Go to File. And then New dynamic
web project. You to give your project a name. So we have a completed 10110 to this project will
be naming as 123. And I will demo. This would be our demo with
Project and justify it. We can keep it as it is. Just click on next and the next. And now you can click on
this and generate WebEx. And we know we have all
the details which will be provided to the solver
in order to launch our website when it is
deployed on the server. Now, click on Finish. Okay, Now I will simply close all the
files which are opened. Now go to this demo project. And now inside this, if you go to source main
web app and whereby enough here you can see
you have dot xml file. And for margin, I mean not
using the subnet and the JSP. Together, we need to create
one servlet at one JASP. So let's start. Just right-click on the project
and go to New and select. Okay? So we need
to give package. So conduits of light
will be our package. And the class name. For the class name you
can give any name. But here I'm going to
simply do an add operation. So I'll be naming it as AD. So I'll be basically taking two numbers and
generating the sum. For that. I'm creating this. Absolutely. Okay.
Now click on Next. This will be our URL mapping. Absolutely, fine. Then click on the next. Okay, so for this one, I'll be using to post. You can move this to get
and click on Finish. Okay? So you can see this default constructor
which we do not need. So we'll tear off. Okay? And here will be
removing this things. So we have a clean code now. Now, you can see this red
lines which are edits. Now you already know how
to fix these errors. For fixing these errors, go to your Properties of the project and then
search for project facets. Click on it. We'll do runtimes and select the server we
just Apache Tomcat name. Click on Apply. And instantly you
can see all the red. Processor can click
on Apply and Close. Project is fresh and t. Next, what we need, we need a JSP file. So go to the web,
right-click New. Then JSP file. Okay? Now give it a name. Index JSP. Click on Next and then Finish. So here I will give it
a title, card numbers. So simply we are going to
create a HTML form here. So for creating the
form will be using the front deck. Okay? Action will be the
name of the server. So for us the name of
this overhead is adsorb. Let okay. So you need to give slash. Why do you can also
skip the slash if, even if you give x of t, that will also not be an issue. So remove it and
write. Well and good. Now we need to also
verify the method. So I think we use the
post method you do post. So that's why we need
to use method is post. If we would have used
methods get here. So if you would
have used to get, then we're given here
the method is GET. I hope you know the difference
between post and get. And get will see the request parameters
in the URL enforced. We do not do it. Okay, Now we'll be
using to input. So input type equals text and give it a name. Num one. Similarly, we can use
another input text. Before that, I will be using a level that it's clear for us. So in the level, one, gave a colon. Okay, now simply give a beer. So the next input
starts from next slide. Okay, now I'll simply copy this level and
input and paste it. So this will be number two. It is not fixed. It, okay. The name should be numb two. This looks good now. And then we'll have
the submit button. Input type equal to, submit value equal to, okay. It can end it with a slash. Okay? So this is
alpha, which is ready. But simply save this control
S you can use to save. And the justifies ready now, we need to manipulate
this ad led fight. So first of all, we need to retrieve num one
and num two from the form which will be
submitting for that int num one. Now from where can we get
that particular number? We can get it from
the request HTTP. So lytic mass in
the request will have that particular parameter. So what we'll do is
we'll do request, get pedometer, get manometer. And inside it we can write
the name of a meter, which is num one. Okay? Now you can see a red line because there is a
mismatch you need to change now one string. All you need to change. This particular tool for that
will be sending it to end. So we'll use Integer.parseInt. So integer bars. And say this will have this
request dot GET parameter. I will close the bracket
and we have our num one. Next, we need to retrieve the
num two from the request. So simply copy and paste
this and change num one. Num two, change the
parameter name as well. So remember the parameter
name which we are using here. It should be same as
the name you use here. So if we have used num one here, that's why you are
using num one here. And we have used now to here. Similarly, Williamson
number two here. This should be same as what
you're using that GSP frame. So now we have our num one
and num two. Well and good. Now next, we need to
find out the sum. So for that, I'm
simply going to take a variable sum and just
add these two elements. Now, we need to print it. So how can we print it? If you already remember, let me go to this
particular lead. This how we used to rent to them someday sponsored get
Writer dot print, LN. So we can do a
similar thing here. You can copy this. Go back to your acts
of lead, paste it. And here instead of
this Hello World, we can write some shouldn't
be insane the groups. So sum equals and then plus, and then this some fake it. Okay? So this is going to print
the sum on this thing. Let's save this control S. So our actual lettuce
ready or index.js besides, just close this one, because this doesn't
belong to this project. Now will be learning this. So right-click on the
project and Uranus. Until I think by now it will be in the running
projects on the silver. So they move the
one you'd not eat. We need to run only 103, so we'll go ahead with it. Click on Finish if
they start to one. Okay. We have this form. So why did it just
launched this form? So if you remember, it is
because of this web dot xml, the welcome file we have
already mentioned to launch index.js be so it will find index.js be in the
web app folder. If it is there, it
will simply launch it. So let's go back. So num1 and num2. Let's add. So I'm going to add three. With two fans, it
is five, we know, but let's see if the sunlight
gives us the right answer. So click on, add. The silver nose. So it's showing so
sum equal to five. That's correct. Now it is very small. So what I'll be
doing is I'll use H1 tag for our
better visibility. You can use H1 tag. And then again, save this. As usual, we need
to run it again. Silver next. By just not giving us. Let's save this. I
hope now it is saved. Right-click there
until don't get next. Yes it is there. Finish. They start the solver. Now we'll add something else. Let's add 63. Months is nine. We already know. Let's add and check. Sum equal to nine. It's
working perfectly fine. So now you know how you can
use the JSP file and this all together and generate
the answers. So you can submit the form, you can see the answer here. So what do you use
this we use to request dot GET parameter in order to fetch the better
the foam pad meters we just submitted
to that request. In the next video, we'll be
learning about annotation. So why we are using this address web servlet
that really get to know. So thank you for
watching this video. Stay tuned to the course.
8. Annotation: Hey guys, welcome
back to the course. So we're done with our
103 demo web project. I would recommend
you to try this out. I mean, you can create
a new web project. And instead of doing
addition here. So instead of addition, you can do anything like
subtraction and multiplication. You can simply create this form. And instead of add, you can simply do other
stuffs like multiplication and subtraction and run it on your server and
see if it is working. Now. Next, what we're going to do is we'll be learning
about the annotations, annotations and other thing. But you can see this
web service rate. So this is a notation. Okay? So what this
annotation is doing, it is actually declaring this particular sublet
as a web servlet. And it is also doing
a URL mapping. So this is how when the
server runs this program. And because of this annotation
at dread webs of lead, it is able to
understand that yes, days or so read the name axon and this is the URL
mapping for it. So there are two ways by
which this can be done. I'll open a Notepad. So two ways. Okay, I hope you're
now I can see number one is true and notation. Number two is true. That web dot XML, which is our
deployment descriptor. So we can define the subnet. We using the annotation
at the red web servlet. We can use XML
based declaration, which is our web dot. So these are the two
ways we can declare. In the next video,
we'll see how we can declare it in
the web dot xml. Thank you.
9. Xml based Configuration: Hey guys, welcome
back to the course. So in this video, we'll see how we can create and the actual web servlet
mapping into our web dot xml. For that, what I'm going to
do is I'm going to create a new web dynamic web project where it is here. So when 0 for the project. Using Excellent. What do you can do is from here, you can select the
target runtime so that it doesn't give us the edit
which we are getting earlier. Apache Tomcat nine,
you can choose, the rest of it will be same. You can also do it from
the project facets. As I had shown you, we can go to the properties of the project
and do that from there. But from here also you can
select the target runtime. Now next. Next, and check this web dot
xml deployment descriptor. Now click on Finish. This. We need the actual lead
into this project as well. So what I'm going to do
is I'm going to copy. So copy. And inside the double for
loop and simply paste. We have x over here. Then good. Similarly,
we are going to copy and paste our
index.js be so copy. They stood in the liver. Like click and raise the best option based. Close all the files here. So now in the demo 104, you have that to let index.js. Now what we're going
to do is we'll simply removing this seam, this. Okay, now let's run it and
see if we get any output. So remove 103104, finish. Restart the server. Okay, so we're getting the form because we
have the web dot XML. Let's do word four plus five. Click on Add. And it is showing not found,
what is not found. This ad dot subject. So we need to configure
that in our web dot XML. If we're not going to use that
notation at the WebSocket. Let's go back to your
live web dot XML. Okay? Now such force of lead, lead is here, if on that. Okay, So we have the subnet tax. Now we need to give it a name. So let me, okay. So the name for us is linked. And what is the next thing? Next week, yes. So let class. For the class we need to give the fruit part of our solid. So this is our excellent. So from here we can
copy com dot dot. So you need to give the
full path of the class. Okay? Next, we need to do the URL makin
for the URL mapping. Goto. So let me again, okay. Now, let mapping will again
give the name of this object. So I'll just copy it from
here. Paste it here. And we need to give
the URL pattern. You are in fact on. Url patterns should be slash. Okay? So now we have everything
configured here. Simply save this. So Control-S. Again, we're going to run it, restart the server. And then we have the
phloem four plus five and then sum equal to nine. So earlier we were
getting this error. Four, not four, not found error. But now we get the right answer because
of configuring it. And now web dot xml, there are two ways. One is through annotation. Annotation is this one, select, and the other is to web dot XML using this select
and subnet mapping. So I hope now you know how to do it using a notation
as well as the XML. You would a try. You can create a similar project in
your Eclipse IDE. Tried using the notation
as well, less than XML. Thank you for
watching this lesson. In the next lesson.
10. GET Requests: Hey guys, welcome
back to the course. I hope by now you're
enjoying learning the legs. We are done with 103104. Next we'll explore some
more on this demo projects. So again, click on File. New. Then dynamic web project. Give it a name. So 105 demo project. And the name should be good. So I'll be showing you how you can send a get request
to the server. So earlier we had seen post. So here we'll be seeing it. We have the runtime configured,
everything is fine. Now click on Next. Again, next. Check this one and finish. Okay, so we have no phase here. What we're going to
do is we're going to simply copy all files. It will be much easier that way since we already created it. So appeared from here. And paste it in the Java folder. And login copy from the web app index.js be. Copy it. Come to the web folder. Right-click and paste. As simply close this one and also close. I'll
let Apps from here. In the index.js be. What we're going to
do is we're going to remove the second level. Here we have texts
instead of the name. Will be not passing a string. For the string, I will
give it the name is STR and enter your name. So basically we'll be submitting our name as a string
it into the form. And it will show a welcome
page from the solid will configure how we can
see the welcome page. Change the title as
well to welcome. The main thing, which
is the method should we get not post at solid? We'll rename this so we can
give it as the muscle blood. Okay. Control-s, this is saved. Let's go to this one at solid. Now when you do
change the name here. So right-click, click on the refactor,
refactor rename. And this is also going to
update our references. So given MS demo, next, next, finish
our demos of lead. And we're going to the notation for the name, not here
inside the brackets, for the name slash. Okay. Now we need to get
the parameters, but here we're taking the
integers, this one completely. And we'll type string. And then request dot. Get better. And the name of the
parameters is there. If you remember, in the form, you have given the name is STR. Okay? And then there is a very important change we need to make that is we need
to change to post width, do get so quickly, change it. Do. Since we're using the methods
AND gate, this is fine. Here will be not using the
sum but welcome space. And then name for our visibility will
be using the H1 tag. Don't forget to close the tag. So we have what do GET method. Say that we are fetching
the request parameter, we are displaying the output. And we also have indexed or
JSP where we have the form. Everything looks good. So now save all the changes and then this then
this thumb kidney. Next. Remove this 104,
we just need 105. Click on Finish. Are you sure you want to
remove the resource? Yes. Okay. Start to silver. Enter your name. You can
enter any name, John. And that's showing
fluorophore not found. Okay. What is they show?
The more dots on it. So if you remember,
we had used sure. So we need to make
that change here. Action should be short
and not demo dot. So let this thing, which we have mentioned here
as a web server session. So we'll be using show here. Okay. So that's why we weren't
getting that for all four because they
couldn't find this. Sure. Because this phone
was pointing to demo. So now I'll make another change it
instead of just giving the nameless so it will
be more appropriate. Okay, so let's run it again. It's good that we're
getting some errors because that's how we will learn how you can resolve that is
when you get them. Okay, enter your name. John and submit. Welcome John. So now you can see something we just changed
for this example, that is Show and there is a question mark and
recall to John, since it is a GET request. So we can see our request
parameter in the URL. Now, if we change it from
here, John to Jenny. Now you can see, welcome Jamie. For GET requests, we
can manipulate and change the request
parameters from the URLS with so we can give anything
they want to go too high. It will display that. So now you know how to fetch
and the request for good as well as post and how you can submit this form using
getMethod force method. So give this a try at your site. Thank you for
watching this course.
11. Request Dispatcher Demo: Hey guys, welcome
back to the course. So in this video
we'll be talking about redirection in Servlets. So there are different types of redirection which is
available for sublet. So let's look into them. The directions for
what is redirection. The direction is
nothing but when we move from one web
page to another. So number one would be the request dispatcher. Okay? So using requests dispatcher, we can redirect from one
web page to another. The next one is,
we're reading it. We can send a redirect from
one subject to the other. So there are two
ways we can do that. First of all, using session. So using session
attributes, we can do this. And the next one
is using cookies. So I will show you
how you can redirect using requests dispatcher and
also sessions and cookies. In this video, we'll focus
on the request dispatcher. So let's get started. Now open your eclipse. Okay. Now we'll create a new project. So I think in the
demo web project, we had performed
some addition rate. If we go there, we had performed
addition of two numbers. So I'm going to reuse
this project in order to show you the demo
for the direction. Just copy this and right-click. And then rename this project. I'm going to rename it as 106. They move a project. Instead of that, we can write using requests dispatcher. Okay, now click on Copy. This carpet for us. We can go and check the files. Before that I will just
close all the open files in our editor and then go
to this index.js P. And then Java resources. We have at where we're
adding two numbers. Now for this one, what we'll do is after we
get the sum of two numbers, here we're printing and trade. But in the redaction example, what we'll do is we'll
redirect the sum. We will be redirecting
to a different web page. And we'll be sending
this some value. There will be finding the
square of the sounds. So let's do that. For that, what I will do is
I'm going to simply copy this axle lead within
the same package. I will paste it before
pasting it and rename it. So it should we name this
squared square of lessons? We're going to find
the square of the sum. Okay? So we can, okay. Now we need to make some
changes. First, do this. Absolutely. Okay. So we won't be
printing the result. So let's comment this out or you can completely
remove this as well. Instead of this will be
first setting the request, actually request
dot set attribute. Name that attribute as some
variable should also be sum. So sum is assigned to the sun. Okay? So in the request, we have said this variable. Now, we will be creating an object for the
request dispatcher. Request dispatcher. Okay. We can name it as RD equals
then request dot get. So you can see requests that get, GET, request dispatcher. Okay, so we're
going to select it. Now here in the argument, we need to give the
name of our servlet, which we are going
to redirect to. So for here, I'm
going to name it S. S Q. Okay. That's fine. Now, forward this request for that we're going
to use id dot forward. It takes this argument,
request and response. So this should be as it is. Now I'm going to save this. We're done making changes
in our acts of lead. Now we'll go to the squares. Now see the name of this
latest quest of lead. And you need to do the
URL mapping for this. Now I'm going to do
the mapping to SQR. So if you remember, here we made the mapping to SQL, we're redirecting to a scalar. So the URL mapping for the
server should also be SQR. Okay? Now, next thing what we
are going to do is nesting. What you're going to do is
this numbers we do not need. Because the sum which we are sending from here
is being deceived here. Now here instead
of loopholes to, we'll change it to do good. This is good now. So in sum, we will remove this. Now some will request dot get attribute and
the name of the string. So see we were using here
request dot set attribute rate. But here we'll be using
request dot get attribute. Now this is actually, we need to cast it to integer. So an integer casting. Okay? So we have the sum in
this sum variable. Now, we need to find
the square of it. So instead of sum square
and the value would be some into, we're squaring it. Now save this. We're done making the changes. Let's run. Solver. Go to your Tomcat, wishing name, remove
the previous one. We only need one to
six and then finish. So we have the form here. We need to give number
one and number two. And as a result, we'll
get that square root of the sum of the numbers. So we will be giving 23. So 23 adds up to five, and the result should be
Phi squared, which is 25. Let's check. Okay, so we're
getting a method not allowed. Let's check that what it is not supported by
the resource Veritas. Add some light, okay, HTTP request post is not
supported by this URL. So let's check what, what is the issue in the ad. So let's let's go and go
to the index.js be yes, we're using at servlet. Here. We'll be using the post. That's fine. Everything
is fine here. Let's go to the squares on it. There is another method which you can use instead of do get. Let's try with that. So that is called solvus
public wide service. Let's see. If this is also an issue. Then S, then on solar. Next, finish. Start the server. So remember when you
make any changes, do not forget to start suddenly. For the changes to the boiler, we have those very cold to 25. So we had to use this method
instead of do get method. So as we already know that
when we're submitting a form, we need to provide the
method here, post or GET. Here we are submitting
the form that's where you're using host. But for the direction
we do not need also get we need to use the service. So this was all for this
request dispatcher. How you can redirect using
the request dispatcher. Thank you for
watching this video. See you in the next lesson.
12. Redirection using Session: Hey guys, welcome
back to the course. So in the previous video, we have already seen
how we can send the redirection using
this request dispatcher. In this video, we will
concentrate on how we can read that it using
the session video. Okay, so let's go back to our Eclipse editor and now
copy this 106 project. Okay, So copy, right-click
here and paste. Rename your project file. So redirect using session. Now click on Copy. We have our one
to seven project. I'll simply close the file. Now go to your java folder. We have active Latin, squares of light, and we also
have the index dot js be. Okay. We don't need to
make any changes to this index.js P wave to go
to our acts of late. Now, instead of using requests, dispatcher will use
the scent redirect. So for that, what we'll do is we'll simply remove that
request dispatcher code. And now write HTTP session, Session equal to then request dot get session. So we will quickly import
this HTTP session. Then it is gone. So we're creating an HTTP
object, HTTP session object. When we are fitting this
request dot get session. In this session we are going
to store our variables. So session dot set attribute. And we're setting this some
attribute in the session. The setting of the
attributes are done. Now we need to send a redirection for
that, right response. Send getting this bond
and this centroid. So click on that. And what do we need to
give you as argument? We need to give them
name or the URL of the lid we're going
to redirect to. So here the servlet
is SQR. Save this. So now we need, we have sent the redirect. Now, in this question of
lead will make some changes. To receive the direct
and show down. Here. We need to first create
the HTTP session object. So HTTP session, session equals request dot get session. Okay? Again, import
the HTTP session. Okay, So HTP session
is imported and we have already created an
object of this session. Now for the Sun, what we're going to
do is we're going to, simply, as you remember, that the sum is now a is an
attribute of the session. The session we need to
fetch the sum attribute. So session dot get attribute. Okay? What is the name
of the attribute some. Okay? So why we
are getting here, because we need to
cast it to an integer. The casting is done. Now we have the sum value, and now we're just printing the square of
the sum on this screen. Will it be saved
this class of lead, all the changes are
done from our side. Now we'll run this and see
though would go to 107, right-click and then
runners, then un-solo. Select the tongue, gets over. Next. Now remove this one. Dealer
Six, need to run 107. Finish on, okay. Start the server. Again, we have the form. Let's write it. Two plus t should be five
and the square should be 25. And we can see the output. So you may have a query
in your mind that why we are seeing this
103 demo project. The name of our project is 107. Redirect using session. So let me tell you this
is because we have been coping this particular
project from the source, which is 103, they move
apart while coping. Certain things are not renamed once we're
renaming the project. So since we were
copying from this one, so the base URL has not changed. It is still 103. If we go to the
previous example, then also this 103. So nothing to worry about the water because
we were copying it. That's why we're
seeing this URL. So if you don't want to copy, you can create a new
dynamic web project and write all this
code from stat. But since I want
to save some time and focus on the
learning purpose, so that is why I am copying it. Okay? So now you
know how you can send a redirect using
the session attributes. Thank you for
watching this video. See you in the next lesson.
13. Redirection using Cookies: Hey guys, welcome
back to the course. We have already seen how we can send a redirect using
the session attributes. So in this video,
our focus will be on how we can send a redirect
using the cookies. So let's get started. Now, go to the Eclipse editor. And from the ones that are
seven, copy this project. Based it, rename it. Okay, so it should be 108. And then redirect using
session should we did, I do think cookies. Okay. Now simply copy. Now you have 108. I'll quickly close all
the previous fights and I'll just open that. Once we just created. So square root of lead, we have the index dot js p. So this was our session using which we were
sending the redirect. We're setting an attribute. Now we will be using cookies. So let me remove this
one. The session part. Now for the cookies, just write cookie, cookie. So we're creating an object
of the cookie class. Hokey, mind spelling. So new cookie. And then we said cookie, attribute and value.
So some common. Okay. Now let's
import the cookie. Okay, imported. Now what is the issue? Change type of sum two strings. So Cookie only accepts
the type is string. So we need to change the
type of sum 23. Okay? Let's remove this.
It's not needed. So write string some value equal to quotes, and then this will
convert the string. Now instead of sum, you can use some value here, so someone can use it. Okay? So we have already
said the cookies. Now, how can we send this cookie while we're
sending this redact? So for that, we need to attach this cookie
with that response. So response dot at cookie to mention the
name of the cookie. So this is how you
can add the cookie. Once we're done
making changes here, simply save this
to your squares. So let's now you can
see session here. We don't need the session rate, we need to remove this. Now. We need to again,
right here, cookies. So there is a change here. I mean, while we were
setting the cookie, we could use a single cookie and this object we could create, but while receiving it, we need to I accepted
as an array of cookies. Cookies equal to the dot. So here in this cookies,
what is the issue? Okay, And one more thing instead of cookies is
shouldn't be cookie. So this should be a cookie. Now, important cookie
from this java x. So we have the cookies, all the cookies which are sent from the axial
lead to here. Inside this cookies. Now will simply run a for-loop for each and every cookie from this cookie. Okay? Now we need to check if the sum exists or
not enough cookie. Cookie. Dot get name. Okay? So here we have getName. So what should be the nim sum? So if cookie dot getName is sum equals sum. Okay? So if the name of
the cookie is same as some argument to match getName. Okay? Okay, So we do not
need to give any name here. Just give cookie
dot getName where it will face the name
of the cookie and check if it is dot
equals some FeS. Now what we can do is we can create an integer
sum equal to 0. Now here we can assign the
value to this semicolon. Then dot get value. Okay? Now again, we need
to, I think, cast it. So change type of sum to
string or typecast it. So we're going to
simply type cast it, integer, dot, parse. And okay, so now we have some value here. Now we're printing the
square of somebody. This is how you can
retrieve the cookie. Use it in your soul. Now just save this. So to run it, right-click and
then mass than on Solver. Getname. Next, remove the 107. Finish. Okay, start the server. Wait for it to run. Let's
give a different value now. So four plus four should we
eat? And it's quite sure. Let's see. Yeah. So we're getting
the result. Okay. So let's go back. So this is how you can send a redirect using
the cookies, okay? So first of all, you need
to create an object, an object of the cookie. And then in the responsively
to add the cookie. And this response goes, does this end redirect
to the square, which is here, square. So the response here
is a request here. Remember that now Cookie, Cookies, we add, fetching
an area of the cookie. We are facing an area of
the cookie objects here. And this is how we can do it. Requests don't get cookies. And we are running a
for loop where we can, we are fetching all
the cookies which we have received
from this request. And we are checking if
this equals the valve, the name of the cookie
is equal to sum. Then we're, retrieving
that some value. And then we're printing. This was all about redirection. Thank you for
watching this video. Stay tuned to the course.
14. JSP Request Dispatcher Demo: Hey guys, welcome
back to the course. So now we know how to
send the redirects using the request dispatcher
and also session cookie using them in the select. Okay, now let's see the
redirection in JASP as well. So for that, what I'll
do is I'll simply copy this project and then paste it. Now, rename it to 109, rewrite it using
requests dispatcher. Okay. In JSB. Copy this. There is no like any convention for the
names of the project. You can name it as
per your convenience. Now, here I'm going to go to the Java, Java resources here. I'm just going to
delete it because we do not need this Alexia. We will just be walking is in DSPs and how we can send
the indirect space. This is our index.js be, I'll quickly close
all the other fights. Okay? So this was our index.js
base when we're submitting numbers and
when it does some of it. For the sum, again, I'll create a new JSP file. Okay? So kid is be fine. Then retest some. Don't. Or you can name it as
add non-adjacent. Okay. And click on Finish. Okay, So this is our JASP. So now in the app.js
be you need to receive the parameters which
are being set from the form which we
are getting here. Now in the action, we will write ab.js be since
we're not using the adsorb, let your routine you to GSP. Save this. And then let's go to Edit JSP. And here, your first
except the pedometers. I'm going to open a script. Here. Write int num equal to request dot, get manometer. And then the name of the
parameter which is num. Okay? So you are getting some error. I think we need to
cast it to integer. Simply fasted. It's still showing. So let us use the Integer.parseInt integer n. And then inside this weekend, okay, so we have now
retrieved num one. Next we're going to retrieve
num to copy and paste. The same syntax will just
change the variable names. So it should be known to. The parameter name, should
be number two as well. We have received num
one and num two. Now we need to find the sum. So sum equal to
num one, num two. So we have this sum num. Now we haven't done
any redirection, but now we are going to do it. We're going to send us some attribute to another JSP file, which will be named a
squared dot genes B. And then we need to find
the square root of the sum. So for that, first of all, we need to add this attribute. So request dot set attribute and then some comma. So this is going to set the
attribute to the request. Now we need to redacted. For the redirection. We need to get lead context and save this. We need to write GET
request dispatcher. We have it here. So get some context and then
get request dispatcher. Inside the request dispatcher, we need to give them
name of the JSP file. We need to redirect and then dark forward the request
and response arguments. So it is a one liner code
in the South later ID. Let me show you just to
compare the changes. If we go to the Java folder
and we go to this act. So here we were creating our
request dispatcher object. And then we went calling
this id dot forward. But it is what has
been created from the request dot GET
request dispatch. Okay? But unlike in
the Android JSP, we're doing it in one line. We are calling this
solid context. And from there we're calling
the get request dispatcher. We're giving the name
of the CSV file. We want to detect two and then dot for request and
response objects. Our work for adder JSP is done. We have redirected to SQR dot. So we need to now create
a skew or not JSP. So go to whoever
right-click New. Then JSP file. You're going to name
it as SQR dot GASB. Just click on Finish. We have our new JSP file
along with ADD and index. Now here we are going to receive that particular
ethnic group. So again, I'm going to
open a script right here. Now. You need to provide the code for retrieving
the attributes. So int sum equal to
request attribute. We had said that attribute, then we will use get attribute here and the
name of the attribute. Again, we need to typecast
it so integer bars and then within the bracket. Okay, so what is the issue? The metric person in
the type integer is not applicable for
the arguments object. Okay, So it is treating
it as an object. So remove the bias and
then just write int. And let's see if
this is the issue. The issue is resolved. Okay, the next thing we need to plan to the square
of dy attribute. Here. We're going to write
out dot print LN. And then within that
unit two, right? Okay, so we need to also
get the square of the sum. So create an attribute
equal to sum. Okay? So here we'll be
writing square equal to then plus and then squared. Okay? I'll show you another way by
which you can also print. So let's do this 1 first. Let's run with this one and see if the code is running properly. So I'm going to right-click
and then S anon server. Tomcat. Next. Remove 108. Finish. Okay. Please start the server. Let's quickly input the values. So four plus two should be six and the square should be 36. We can see some edit here. Http 500 status,
internal server error. So let's see what is
the error we have. In line 16. There is an error, so good. So let contest GET
request dispatch, okay, there should be a
slash before SQR dot GSP. Let's do that and see if
this one is also already. Just add a slash. Safe. Now, again, run it. Then I'm silver. Next. Finish. Again. Let's try four plus to add. Now we get square root 36. Okay? So this is how you can
redirect using the GSP. So now here I'll
show you another way with which you can
print the result. So instead of this one and
just quickly commented out. So instead of this one, you can use this to
print it as well. Using H1 tag. Didn't say this, but outside
H1 tag, within this right? Squared. Close the H1 tag. Save this, and now run it
again until your next. We need to selected. Next. Finish. Again. Let's give a
different number now. Seven plus two. Which would be nine and
the answer should be 81. Yes, we get it. Okay. So this is how we can use
the requests dispatcher to redirect request from
one JSP file to another. In the next video, we'll see
how we can use the session. Don't redirect our course. Thank you for
watching this video.
15. JSP Redirection using Session Demo: Hey guys, welcome
back to the course. So in this video
we'll see how we can redirect JSP files from one file to another using the need direction, using
session attributes. Okay, so we'll just copy 109 project and paste it
now renamed the project. So it shouldn't be 110 now. And reediting using
session attributes, JSP. Okay, So click on Copy. So now we have 110. So it'll quickly close all the
dams here and we have 110. So let's see if there
are any Java files. Now, let's go to
SIC main web app. And here we have our ab.js
be index.js be SQR dot JSP. Now, the index dot js
p should be as it is. We have a form. It's redacting I mean, it's submitting the form to this ASP JSP to
make the changes. First, this will be same. We're just retrieving the
parameters from the request. So num one and num two we have, we're calculating the
sum. That's fine. Now we need to add the attributes to the
session and not Request. Session dot set attribute. Some. Here. Instead of the
request dispatcher will be using same redirect, request dot send, direct, and give the name
of the JSP file. Okay? So it's
showing some issue. The method is undefined for
the type HTTP request, okay? So we need to send
it as a response. So response dot redirect, GSP. So I think we did it as did a similar thing for
our servlets as well. Let's go and check to compare. So if you open at servlet, here, we had first declared the HTTP session object and then Session dot set attribute sponsored
sending rate. So this will be same for JASP, only the setting of the object, I mean the Declaring of
the object is skipped. So in JASP, this session
is already taken care. Okay? So you do
not need to create a session object
using HTTP session. When you write session, it will directly take it by default. So this is done and
don't JSP save this. Now let us go to
our SQR dot GSP. Here. We're getting that tribute from the request
in search of that. You guessed it right. It
shouldn't be session. Okay? So Session.get attribute
cell and let it stop. It will be same as it is safe. Now, let us run this
and see the output. So right-click the server. Tomcat. Next, we move on to row nine. Finished. Click on Okay. Restart the server. Let's give some numbers. Five plus two, which is seven. So answer should be 49. Let's take yes, we have 49. Okay. So this is how we can send the redirect
using the session attributes in the GSP from one JASP we can rely
on to the next JSP file. If you also want to explore how we can do
that using cookies, you can do it on yourself. So this will be a practice
question for you, where you need to
send the request, this redirection
using the cookie. Instead of session. I hope you learned something
from this video. Thank you for watching this. Stay tuned to the course.
16. Redirection using JSP Forward: Hey guys, welcome
back to the course. In this video, we'll
see how by another way, we can redirect from one
JSP file to another. So here I'm going to create another project so you can just copy latest project
and then paste it. Rename the project. I'm going to rename it
as 111 and then redirect using ASP forward. Okay? So this is another
way with which you can redirect from
one page to another. So click on Copy. So we have our project ready. Now close all the open files
and then go to your project. Src folder and then web app. Have index, add, square. Okay, So I'm going to
remove this SQR file. We'll see in a different
manner, this one. And I will also remove this one, will have index.js p. Here. Instead of a flower,
we'll be using the DSP forward to
forward it to a new page. And we'll also be forwarding some messages along
with the forward. Okay. So remove the
form and I'll change the title to JSP forward. Okay. Now, right, JSP forward. Okay. So in the GSP forward, you can see there's the stack
and it's asking for a pH. So the pH should be the page where it will
be redirected to. So here I can give a new piece. So let's write f w d dot JASP. So we need to create
this FWD dot JSP. Now, when it passed
some pattern, we will be using
this JSP param tag. And for the value, I'll be sending some messages. So this is forwarded using JSP forward. And let's give this a name. So I'll give it the
name as message. So when we retrieve this
particular message, we need to use this mean, which is MSG, okay? Now save this index
file is ready for us. Now we'll create a new
JSP file which will win named as FWD dot GSP. So go to Web App, new JSP file. Name it as FWD dot JSP. Okay, now click on Next, Finish. Enter a title search. Here we can simply show the
message we just forwarded. Request dot get fatter meat. Okay? And it is called MSG, right? So this is how we
can simply display the message we got or we can save it into some
variable and use it. Based on the requirement we need to use this
gene's be forward. Okay, So let's run this and
see if we get some output. So right-click and then S. Then un-solo. Choose your server. Remove the 110 confidence. Okay? This is forwarded
using JSP forward. Okay? So we add directly
seeing this, instead of that, let's create a form and
forward using JASP. So we will add, I think we can add a receptor. Or should we just be fine? Jsp. Okay, Next, Finish. Move this to the receptor. Okay. Now, if in the next page, you can create a form. The actions should
be the SEP dot JSP. And here you can use
a label message. And then use input. Type should be text and name should we message? Okay? And we need to
have a Submit button. Type equals submit value equal to send. Our form is ready. It will be forwarding
it to receptor dot JSP. And the receptor dot JSP, we need to accept that
particular parameter. So for accepting we already
know it should be string. And let's name it as MSG. So a request, get
pedometer and write MSG. Okay, so we have this MSG. Now, instead of this
one, we will write MSG. Okay? Now save this. And the forward or
JSP should be same because we haven't changed the
name of the JSP pedometer. So let's run this message. Hi, how are you? Send it? We have some internal
server error. Let's also check this. In line 12. We have the issue. Let's go and check in
line 12 here. Okay. So why did this? Because I wanted to show you that if we are
accepting some value, then we cannot send
it through here. We need to send a string on. Okay? So even if we are
sending some messages, it won't be fast. So if we use MSG and then quickly run solver, again, high, let's say. And it's showing MSG, okay? So even if you are sending
something that should be in the double-quotes
for the GSP pattern. So that's why we are not
able to see the message. Recent. Gsp forward can be used for sending some
predefined messages. And if we want to receive
some form attributes and we can use the request dispatcher or
the session or the cookies. Now you can also play
around more on this and see what are the things which we can send and what are
the things we cannot. Thank you for
watching this video. See you in the next lesson.
17. Introduction to JDBC: Hey guys, welcome
back to the course. So in this video we'll
learn about JDVC. Jdvc stands for Java
Database Connectivity. It is basically a
Java API to connect and execute the queries
with the database queries. As such, the create,
retrieve, update, delete, or whatever queries
we run on the database. It handles it from
the Java side. So let me show you the
basic architecture. So we have the database here, and we also have the
Java application. So JDBC will have the JDBC
API and the JDBC driver. Okay? So this JDBC driver
with will help the Java application to execute the queries
in the database. Okay, so this is an
intermediate driver which has Java application to execute the query
is in the database. Now there is also JDBC API. So what it does. So using the JDBC API, we can handle the database
using Java program. So it is basically used for
connecting to the database, then executing the queries and updates statements
to the database. And it also helps to retrieve the results received
from the database. So this is how it works. In our course, we'll be using the MySQL or MySQL database. So this was all about
introduction to JDBC. In the next video, we
will see how we can use the JDBC to connect and execute queries
in the database. Thank you for
watching this video. See you in the next lesson.
18. Import MySQL Jar: Hey guys, welcome
back to the course. In this video, we'll
be seeing how we can create the JDBC projects and thereby run some queries on the database and also
connect to the database. For that, you need to go to Eclipse ID and create
a new workspace. Okay, browse to Dexter. Here, I'm going to
create a new workspace. So click on New Folder, and I will name it
as JDBC workspace. Here we'll have all
our JDBC programs. So this is our workspace. So select the folder
and launch it. You can see the JDBC
workspaces created. Expand the window. Close the welcome message. Fine. So now we can start
creating our project. So before creating the project, we need to fulfill
some more steps. So that is, there
is a prerequisite. We need to add my sick
well-connected in the belt path. Okay? So it'd be creating
a normal Java application. And first of all, we
really get the project ready by adding the MySQL
Connector journey number. But this is a prerequisite. So let's start. So we'll be creating a project. You can go to File
New Project, okay? Do not select
dynamic web project. This will be a
normal Java project for the demo of the JDVC. Later will be also using JDBC in the dynamic web project
when we build our project. Okay, so for now, click on this new project. This will create a
Java project for you. Select Java project. Next. Give you a project, a name. So I'm going to name it
as JD VC connection. Okay, and give the rest
of the thing as it is. Click on Next. This is done, and click on Finish. Okay, so here we have
our JDBC connection. We need to now get the connector jar in
the milk fat. For that. Go to your browser and
search for my sequence. Connected. Okay, so you can download it
from here, dev.mysql.com. So go there. Go to the download page. This will be the installer. We do not need the installer. We just meet the connector jar. Let me see if we
can find it here. Okay. Yeah, Windows. Okay. So it's asking for installing
them, My Sequel installer. So if you don't have my
sequel in your laptop or PC, you get this installer
downloaded and installed. But for me, I think I already
have them, My Sequel. So I will skip this part. Let's see. Okay. So this is the Java jar. We can download it from here. We have downloaded. Now, let's go back
to Eclipse ID. Right-click. Before that we need
to extract the fine. Let's see. Let's
show it in folder. Okay, so it's not as zip folder, it's a normal jar. We can now directly added to our belt,
but so right-click. And then build path
configured but fat. And then go to libraries. Okay? And then add external. John. Now go to downloads. You have done my
sick well-connected. Click on Open, click
on Apply and Close. So this is our project. We do not have the
Java files yet, so it'll be creating
those in the next video.
19. MySQL Demo: Hey guys, welcome
back to the course. Now let's see what are the
next steps for us, okay? So the prerequisite is done. Next. The steps with which we can connect to the database and execute the queries
are as follows. First of all, we need to
load the JDBC driver. Then we need to create
a connection to our database in which we want to make the changes and
execute the queries. And then finally
write the code in the Java program to
execute the create, update, delete, and
retrieve queries. And then after that, the last step would be
to close the connection. Before we can go ahead and
do this was to for me to create a database for
the student. For that. Go to your search and
search for my sequence. If you do not have my
sequence, please download it. So you can go to your browser and search
for download MySQL, and you can install
it from data. I already have it
installed, so I'll open it. The password. Password is indeed root. I'll show you in the code also, we need to configure the
passwords and everything. So they didn't show you. Now here we will need
to execute the queries. Okay? So what is our first query? Could be a database
students. Let's write it. Create database students. Okay? Shrink ready,
okay, one row affected. That means it is created. So loose students. Okay, so now we're
inside this database. Okay? Now when you create a table
inside this database, let me put it here
for visibility. Okay, I hope this is visible to, you know, create the table. So for that create
table, students. And you need to give the fields. So integer for the role should be our primary key. Then we need the name. Then SET 15. Okay? So not necessarily, you
have to give 20 or 15. This is the length
of the string, so you can give it as per the
way you think it should be. I think for the city 15 is
enough, so I'll keep it 50. We're done writing
our Create Query. I'll just press enter. And it is created. How we, how can we
see this created? We can use this show tables. The tables you can see
students just created. Now we'll do DIST,
which is described. Students. Don't forget a semicolon after every command
you're right. Yeah, we have this field
S role is named SET a type for Israelis and
it's named a city worker. Role as our primary key and
there is no default value. So the database is created. Now, we can go ahead
with the next steps. That is loading the driver
and creating the connection. We will do this, both of these steps
in the next video. Thank you for
watching this video. See you in the next lesson.
20. Create JDBC Connection: Hey guys, welcome
back to the course. So in the previous video, you've seen that we have already created the database
students dB. And we've also created
a table students, where you have this fields as through its name and a city. Now, in this video, we'll look into these two steps. We just load driver
and create connection. Okay, so let's see
how we can do that. Go back to your Eclipse editor. Now. Create a new package first. So com dot JDBC. Okay, Finish. Inside this, we'll
have our Java class. Okay? So JDBC connect. This should be the
name of our class. And let's click on Finish. We have JDBC connect. This class will be used for
performing those two steps. That is loading the driver
and creating the connection. So first of all, we need to declare the
connection variables. So static connection. So there's a connection object. Now, you can click here. And import connection from Java. Dot is clear, lucky. Now we'll create a method. The return type of
the method should be connection and give it a name. Read connection. Okay? And then, okay, So this is
done, create connection. Now what we'll do is we
will define the gradient. So first step, if you
remember, was Lord framework. So how can we do that? For that, we need to use
class dot floor mean. We already have
this method here, plus dot for name. And inside this we need
to give them names. So my sequence. So this will be our driver dot JDBC driver. Okay, so we're loading
the drape. Let's see. We need to surround it with
try and catch. Let's do that. Okay? So a driver is loaded. Now inside the try only I will
write less than two code. So after loading the driver, what was our next step to
create the connection? Number? To create connection. For creating the distinction, we need three parameters. Number one is the user name, string, username, equal to. So by default, we
will have rho times over username and also the
password for my secret. If you have changed your
username or password, then you need to give, as per the changes you've made. So password is also okay. Now we also need to
give the database URL. Url. Then give JDBC colon, my sequel, colon slash
slash local host. So our sequence is hosted
on this 3306 port numbers. So to give the port
number and then slash and the database name. So for us it's to density. This is the URL
you need to give. So now we need to
create the connection. So equal driver, manager dot get connection. Here you need to give three
pedometers URL, username. Now, I think we need to also see surround
it with try catch, an exception to
existing catch clause. So since it is already
waiting Tricare, so I will do this, Add exception to existing trait. So it throws up SQL exception. We need to handle that.
Now there is no error, but we need to return the con. So we will write
return statement here. Or you could have
also written it here, whatever you wish. I think it's better to return it here after the catch clause. Okay? So the JDBC connect
Java is ready for us. Now we will execute by
creating another class. Let's name it my
application. Okay? And it should have the
public static, void, main. Click on Finish. Remove this command. Okay, so now from here we need to get the connection ready for creating the connection
first before we need to create an object of
this JDBC connect. So create an object for two new JDBC. Okay, now we have an object. Now from here we can
create connection, so it will return us
a connection object. For that, I will retrieve that connection
on fit into this. Okay? So JDBC connect with
God, create connection. Okay? So this one, then all the code which is
inside this create connection and written as the
connection object. Again, import that
connection class. Now, what do we need to do is you need to see if the
connection was null or not. So if the connection
not equal to null, then system.out.print
Dylan shin. Successfully. You need to bring
that connection. It was not successful
or not established. You can write any message
because this is just for demo and learning purpose. So I think we are
done with the code. Now, let's run and
see Java application. And you can see
connections at this one. And there is another some
logs we have in the console. So loading class calm. My sequel, JDBC driver. So this driver class
is loaded first. And then this calm my sequel
JDBC driver was used, but the new driver
class name has changed. Its CJ, just taken by default, the driver is
automatically registered. So you do not need
to manually give it. And the connection
is successful. In the next video, we
will try to execute some queries and see
if that's working. Thank you for
watching this video. See you in the next lesson.
21. JDBC CRUD - Create Operation: Hey guys, welcome
back to the course. In the previous video, we have seen that
how we can create the connection and
load the driver. So in this video, we will start with
running our queries. So first of all, we'll
start with Create. So what I'll do is I'll simply copy this project and paste it. So name it as JDVC clicked Copy. So in the JDBC package, we have the JDBC connection file and also my
application, not jama. Now the next thing is we need to create the student entity. So let's create a new package. Com dot to the BBC dot n d. Okay? Now inside this will create a new class name
with this student. Since we will be dealing
with student here. That's why I'm creating
a class for that. Check this one constructor
from superclass. That's fine. And just
click on Finish. So we have a Student class. Now what are the fields the
student class should have? We can get it from here. It should have a
strong name and city. Okay, So let's do that. Let's declare the
class variables. So int string S9 and string SAP. We have all the fields
defined in this entity class. Now we set some
getters, setters, and constructed
parameterized constructor because we already have a
default constructor here. And also a toString
method for that, you need to go to the Source. Click on this generate
constructor using fields. Select all the fields
and click on Generate. We have our parameterized
constructor. Now. Next we need some
getters and setters. Generate getters and setters. Select on gender. And the third thing is to
generate toString method. Okay? So Jen, our student entity
classes done, we'll save this. Now next, we will need to
perform the crud operations. So for that, I will
create another package, dot JDBC dot current. Okay, Finish. Now create a new class
here, JD DC current. And click on Finish. Now inside this
JDBC credit will be performing our friend
operation that is create, read, update, and delete. In this example, we are
focusing on the Create. So for now we'll just create
the crypto student method. Okay? So for that, great public and Boolean,
create student. And the parameters for
those should be student. Okay? And the connection. Okay. Now we need to import this
class Student and connection. So we'll quickly do that. Import connection
and import student. Okay. Now let's see how we can
create the thread for creating the ferry you to write
string equal to. So what we're going to do, we're going to insert,
insert into student. Make sure this will be
the name of the table. So let's check what is the
name of our table at students. So the name of the
table should be. Lexeme as the one you created, the word mess up on
the name of the table. Insert into students and then values inside this will
give three question marks. Why these three question mark? Because we have
three fields for us. I'll show you. We have
a stroll, a STEMI city. That way we're using three
question marks which will be filled with parameters
in this method only. So I'll show you how
you can do that. Now, we need to create an
object for prepared statement. There are two things In JDBC statement and others
prepared statement. Prepared statement
is used for running the exit or running or executing
the dynamic way. Okay? So prepared statement. Create an object
equals and then conn dot and get prepared statement. Inside this, we need to give
our parameter, we just stop. So what is it saying? Atkins took one,
we don't need to add us to corn.
Let's do one thing. Let's go ahead with the try-catch and let's see
if that resolves or issue. Let me put it inside a try catch. Clean. But still it's
showing some error. I think we can change it to
conduct prepared statement. What it is showing change
to prepared statement. Now the issue is resolved. Next thing is to set
the parameters here. So how will we get
the parameters? I'm in the role as name and
city from this student. Okay? So we'll do ps dot set. Save this. We're going to set
the first parameter. So one comma S DOD, DOD. Okay, So from this
student object will get the rule from
where we'll get distorted will be passing
it from my applications. I'll show you that as
well, how you can do it. Let's get not p is actually it should
be prepared statement. We need to use the object. Okay? Now it is fine. Now let's copy this for
the rest of the event. So next thing should be set
string for the student. Mean. What should we do? This? Should we get
S name, okay? Next. Again, not int, string. And then three. Okay? This one. Okay. So everything is done like setting the prepared statement and running the query from here. Now, what we'll do is we
will create a Boolean here. So Boolean created since we need to return a
Boolean equal to four. And so first of all, the Create, it will be false. Okay? Then created should be true if the query is executed. Okay? So write P, prepared statement, dot execute, update. We could have written
execute query, but there is a reason I'm
using this execute update. This is because that if the, in certain cases, suppose
the role is duplicated. So in that case, it will only execute update. It will only create that
particular student user. The student role, that is the primary key is
not duplicated. So that's why we use execute it. And then we created equal two. If this thing works fine and it doesn't
throw an exception, that created variable
will be true. Now we will return
it, returns it. Frame, save this,
and quickly remove these two findings and
go to my application. So here we read, setting the connection and creating an object of the JDBC connect. Next we need to create
an object of the JDVC. Jdvc. Jdvc. Jdvc. Correct. Okay. So important. Jdbc credit. Okay. Now we need to pass the student and the corn into the method which
is create student. How can we do that?
First of all, we need to create
a Student object. So students do d
equal to new student. And we can pass the rule name. So let's name of John. And the next is the SciPy. So safety would be New York. So this one we need to
actually get inside. They didn't do the
database, okay? So important the student class, and then we need to
call the create method. So for that rate of
Boolean created, equal two, then JDVC credit. Because we have the Creates to rent in this particular class. Student, student. As TOD, it can get from here and coin it
can get from here. We're passing here. So here now we didn't need to check if the connection
was successful or not. Here we can simply check if the student was
created or not. So if created,
created successfully, some shouldn't be. Fine. Now save this. Let's run and see if it is able to create a student
in our database. Right-click. And then as Java application
created successfully. So all this query has
been run properly. And in my application it
was created successfully. Let's go to our database and see if it does
create it successfully. This is our database
students db. Now, you run this query
select star from students. This will show all the data
which is inside this tube. Yeah, we have rule one, John and knew this was
perfectly working fine and it has created a record
for us in the database. This is all about
how you can run the create query in the
database using JDBC. In the next videos
we will learn about the grid services like
Retrieve, Update, and Delete. So thank you for
watching this course. See you in the next lesson.
22. JDBC CRUD - Retrieve Operation: Hey guys, welcome
back to the course. In the previous video, we had seen how we can
run the create fatty. So we had lake created
this application and this JDBC crud
that we have created, this method creates a student with the help of which
we were inserting a new value to the table students and
executing this query. So this was all about Create. And in this video
we'll be looking into how we can retrieve the
data from the database. So for that, just copy the previous project
and not delete. Just copy and paste. So JDBC retrieve. Okay, copy. Now let us close all the
ones which we used earlier. Now let us open our crud dot Java and our
application dot Java. Okay? Ready visit Connect
will be same as it is. This is just for you
connecting to a database. That is fine. And we also
have our entity class today. We will also not touch this one. So the maintain,
this should mean GDB secret and my vacation. Okay? So this was for
creating the student. So student have just commented in order
to understand, okay, Now we need to retrieve. So first of all,
we will retrieve all the data which are
there in the database. So let me write it. Retrieve students, okay, so whatever
data is stored inside the database, it will come. So we need to now
create a method, public void, retrieve. It can also give
the name is Sean. I'm using retrieval. So they crave all students. Okay. Then open the braces. Okay? Now we need to retrieve
all the students for that. Again, we need a query string. Ready. Then select star from students. Okay? So this is our database query and then
we need to run the query. So how can we execute the
query in the previous example, if you see we have used this
prepared statement, right? But here we're going
to use the statement. So let's see how we can use statement instead
of prepared statement. As I mentioned,
prepare statement is basically used for
dynamic queries. Since this is a static query, we do not have enough. See, here we have
question marks, but here we do not have
any question mark. So this is a static query. And for that we need to
use prepared statements. We can use only statement. Okay? So right, statement, escapement equal
to and then gone. Okay, so winning the
connection, the connection. So that is why we will take an argument for the connection. Connection. Conn dot get, statement, not get sediment, create. Okay. Statement, conduct
create statement here, we have to import statement. Let's see, it should
mean pre-cut, so let's put it in a try catch. Now we need to
execute the query. So for that, we need this result set when
our all the lake, when we do this recursive query will get back some
response rate. So that response we're going
to set into this result set. Result set equal to
statement dot execute. Inside this, we need
to write a query, so we already have
the query defined. So that should be okay. Now, we need to import
the result set as well. Now, inside this
result set will have the response which we'll get back from the
statement dot execute. Okay, so now in the set
we have our response. So we need to now
print our response. So for that, I'll
start a while loop. While set dot next. Until the set has values in it, we can use them. So how can we print that? We can use this result. Here. We can write rho equal, then set dot get in. And what should have
been saying this? That you need to write the
name of the field here. Plus then name this plus for
concatenation. So sec dot get string. Since the role was
of type integer, so we use getInt and this is type is string
here for the name. So it'll be using GetString. Get string as new. Again. The last one is
the D C, T equal to. And then sit good GetString. And within it. Okay? So this is done. This
is how we can print the value, so Control-S. And in order to separate, I think we can use
us this kind of top. So we'll have each record
and then the stash in order to differentiate between the record retrieval
students is done. Now we'll go back
to my application. In my application this was
for creating the students. So what I will do is I will simply write a command,
create student. And for now, I'm going
to bring this out. Okay? Now we're going to write about the students, okay? So how can we call the
retrieval students? We can simply use
the Java object, so JDBC, the object dot. So we have now
decree for students and we're passing
corners argument. Okay? So this is how we can
retrieve all the students. Let's see, Let's save
this and see what we get. So run as Java application. Okay? So since we
have only one value, we can see rule one name, John, New York City. So if we want more students than what we
can do is we can create more. So let me uncomment
this. And now. Just give me a moment. I will quickly. Zoom in it. Yeah, I think this
is much better. So now what we're going to do is we're going to
add another record. Okay. So the rule should be two. And John shouldn't be Jennie. And into New York, we can give Paris. Save this. Now, let's run it.
When we run it, the strength will be
created and we can also retrieve the values
from the database. So let's run as
Java application. So created successfully. Ms. Jenny is created
successfully. Now we can get two records, rule one and rule. If we also go to our
My Sequel client, the command line here. Here also, we can see them. So how we can see you can run this query select
star from students. And here you can see now
there are two entries. One is John, six seconds chain. Okay. This is how you can
create and also retrieve the records from your database for retrieving their two ways. One is retrieved our students, the other one can
be retrieved by ID. So we need to provide
the ID or the rule, in this case for the student. And we need to display the
details of that student, that particular student who's roll we're sending
as an argument. So how we can do that? Let's take out go
to JDVC credit. This was what it was. Students. Copy this command and
let's paste it here. So now we're craving
students by ID, retrieve student by i, o. Okay, let's create
a method for that. So public. Now this time the return type
should be still do because we are going
to get the record of that particular student
and send it back to our, my application from when
this method will be called. Now the name of the method
should be retrieved by ID. And there should
be two arguments. One is the second
one is connection. Connection. Okay? My ID, and
this is the rule. Now next thing, what
we need to do is we need to write a query. So let's write a query string. Ready, equal to select from. Students. Read equal to question mark. Okay? Now, the next thing would be to create an object for
the prepared statement. So this is a dynamic query. So that's why we need
that prepared statement. So prepared statement, we need to create
an object as well. So prepared statement and con, not prepared statement. Then we need to write the query, which is plenty for us. Retrieving the record by ID. Okay, now, let's see what is
the issue it should mean. Say try and get. So let's put it inside. Try and catch. This is fine. No, we didn't set the stroke. So for that, what we'll
do is we will write the paired statement dot set. It shouldn't be,
it should set int. So if you'll see for
the role we're using, set, quickly, change it. Now here, one comma. We have the role here, so we'll write whatever all
will get us an argument. We pass that. The query is ready now we
need to execute the query. And when, once we
execute the query, we're going to get
back some result. So result we need
to store it, right? So for storing the result
will use the result set equal to three paired statement,
dot execute claim. Okay? So this is how we get the result from this
prepared statement. And if there is a valid result, so if set dot next, then we need to
retrieve the result. Now how can we
retrieve the lesson? So remember, the
result will be in the form of role name and city. For that, what we
can do is we can create an object of
this entity student. And we can use it to
store our result. So this is our students. And here we can write std equal to 1 second std set, set a certain way to give rule. Next is std dot set. Its name. And its name should be. We can retrieve from this
set where we have the result set dot get string. And we need to mention
the name of the column, which is a snake in SUD dot set city. And we should get it
from said dot get. So remember whenever you
write the set dot get string, now you can see different
method definitions here. So from here you're
going to understand what you need to give us the argument so you need
not remember everything. You can also take help of this method definitions in order to understand
what should be done. So GetString here, again give the column
index, which is S. Now the student is all set and just return the student object, which is completely fine. Now, let's save this. Now we'll go back
to my application. And this was for
retrieval students. Now we're going to
retrieve by ID or lower. Again, we'll use the
object JDBC crud. And since our method is going to return an
object of the students, create Student object here. Let's name it as student and
JDBC dot retrieved by ID. Let's give the ideas one and the connection coin
semicolon, we are done. Now what I will do is I will
simply meant all this out. Okay? So that we get only
the result from this retrieved by
id serial. Fine. And now we'll run it. So right-click then
this Java application. Okay, so we cannot get anything because we haven't
printed anything. So we need to print it. Simply sits out
and write student. Okay, let's run it and see. Then as Java application. Now we can see a stroll one, John, cities, New York. So how's this out?
Student is working. If you remember, if I go
to student entity class, then here we have defined
this toString method. Whenever we call the sys out
and we pass student objects. So this method is called
and we're getting the output in the form
of this statement. Okay? So this is how we are
getting the output. So this is how you can retrieve all students and
retrieved by ID as well. So let's do another
thing we'll give the rule is two and now
let's see if we get the information for
Jenny application. Yes. We have got the role name
is Jenny and that's it. Yes, bets. By id is
working perfectly fine. So this is how you can retrieve
all students or by ID. I hope this was helpful
and you could learn how to retrieve the
data from the database. In the next video,
we'll learn about how you can update
that database table. Thank you for
watching this video. See you in the next lesson.
23. JDBC CRUD - Update Operation: Hey guys, welcome
back to the course. So in the previous video, you had seen how we can retrieve the records from our
database in my secret, using JDBC from Java. Okay, now in this
video we'll talk about how we can perform
our next operation, which is the update operation. For that, again, what
do your last project? Copy and paste the
name your project. So this should be JDBC. Okay, now click on Copy. Here it is. Open. The First of all, I will close the
existing open files and I will open a new project. Open all the files. Now. We need to not need
to change anything. The student entity also, to keep it intact, we don't need to change anything very touchy. Make changes to this
JDBC and my application. So let's start with JDBC crowd. So we have done
create student korea, recruit all students by ID rule. Now next we'll be
doing update stupid. I write this command here. Student. Okay. Now again, we need to
create a method. So public. Now what this will return again a Boolean if it is
updated or not. And update student should
be the name of the. And then for the arguments
we need two arguments. One is the student object, which will have
the updated data. And then the connection. We have this weird object
and connection object. Now, next step is
to again create a query string equal to update the name of the
table, which is students. Set name equal to
question mark, coma. Set equal to question mark, equal to question. This is our primary key, so this cannot be changed. This should be unique. And for the addition, we can only update either
the name or the city. Now, let us, So
what do you think? Will this be a static
or dynamic ready? The answer is yes. This is a dynamic
query because we have these question marks here
which we need to populate. So static value was this one retrieve what's rent where we didn't have any
question mark. And it was static way. Since the update is
a dynamic ready, so we need to use
prepared statements. So again, use
prepared statements. Check I mean, equal to and then corn
with this statement. So I've prepared
statement is ready. Now we need to set
this value to write. Feared. Stickman. Set string one comma name of the student for setting
enough first pedometer. So where can we get it from? We can get it from
this student object. So good. This theme. Let's see why it is
throwing an error. Okay, this should be
inside the try catch. So again, we'll surround
it with try catch. Those support this statement inside the trachea adjustments. Again, we didn't set
the next attribute, which is the city. So prepared statement. Dot set string. And then two, comma Studio City. And last but not least, we need to rule. So prepared
statement, dot sorry. Yeah, dot set int. And then the third
one, which is solid. So its duty. Okay, everything is set. Now, what we need to do
is execute our credit. So how can we do that? Again, prepared
statement. Execute. If this is successful, we can create a Boolean. Variables, Boolean
updated equal to false, initialize it with false. Then if all things go well, we will set it to true, updated equal to true. Now we need to
return the updated. This will give a
message whether it was updated or not,
true or false. Save this. Now let us go to my application. So we have retrieved by ID here. Now we need to do, okay, So how can we update? First of all, we need this student because
it is retrieving the data. So it'd be using this
student object to update. What we'll do is
student dot set. Suppose we want to
change the city. Let's for Jenny,
instead of Paris, you interchange the
city to London. Okay, Now this should get
reflected in our database. For that, we need to again
call the method get students. So Boolean updated
equal to JDBC credit, which is our object
dot get student. Here we'll pass this student
object and connection. Okay? So if updated, updated, successfully, send another message. So something went wrong. Okay, we are done. Let's run this and
see if we can update. This. Parish should
change to London. Now, let's see. Run
as Java application. It's showing updated
successfully. Let's go to our
database and see if it was updated successfully
or not. Yeah. So instead of Paris, you can see London he had no. Okay. So what I will do is I
will copy and paste here. Just in order to see from here only we
can see the output them. So let's now change
again London to suppose. Why do we want to change it to, let's change it to Moscow. And then and it's updated successfully. And now you can see
it all to named Jenny and as it gets Moscow. Okay? So in this way
you can retrieve the particular fields in the
database using debit petty, and you can execute it from
your Java application. Thank you for
watching this video. In the next video, we'll learn about the delete operation.
24. JDBC CRUD - Delete Operation: Hey guys, welcome
back to the course. So in this video we
will look into how we can write the fatty for delete operation update we had learned in our
previous video. In this video we're
going to talk about the delete operation. For the delete
operation will go to our project and just copy it. Paste the name your project. So instead what I'll do
it, I'll write delete. Okay, due to the
naming convention, just come to the second option. Not an issue. We will close all the open files and we'll
open the delete project. And then open all the packages to make changes
to my application and JDBC? Correct. Okay. So to start with this JDBC crit, so up to update was done. Now copy this command
and paste it. So now we need to delete. Great Delete. Now again, we need to create a method. So public boolean,
delete student. And then inside this we need the arguments one
should we introduce, and others should be
connection object. That is quite okay. Now again, we need to write
the query string fatty equal to delete from the name of the table. Read. Equal to question. Again, it is a dynamic query and we need up to pet statement. Prepared statement. Print object equal
to quantum dot. Now said that
before that we need to surround it with try catch. So we need to set the rules so for that prepared statement. In the first argument
and the value should be. Okay. Now the next step is to then
this odd execute this query. So for executing, we already
know the paired statement. Tort execute, update. A delete is basically going
to make some changes to notability is going to
delete a particular record. So that is why we're updating the table right
by deleting the record. So that is why you
will use this execute. If this delete operation
runs successfully, then we need to set
the Boolean variables. Boolean delete it
equal to false. And then if it is successful, we need to set it to true. So delete it equal to true. And then return the delete it. Okay, So we're done writing our query for the
delete operation. Now let's go to my application and call the delete method. So how can we do that? For now, I'll simply
write all this out. And I'm going to simply write delete cookie. So Boolean deleted equal to JDBC current object. The method we just
delete students for the role and gift to go on, which is token each object. If deleted. And we'll show some
messages that is deleted. Success will show this out. So for the shortcut, you can write S by S OUT and press control
space on the inputs. So that way you can skip
writing this whole thing. Now write something. Okay? Now let us retrieve after deleting in order to ensure
everything is deleted. So let's right-click on our project run as
Java application. You could see students role to Jenny deleted successfully. And now when we retrieve all, we have only John
and non-change. So we can also verify
this from the database. Let's go to our MySQL lane. And from here again I will
than the select query. Now you can only see one record that Jenny and
London record is gone. We only have joined
because we deleted it. So this is how it works. And after completing all the operations
which you need to do, you will need to
close the connection. So how can you close
the connection? I'll show you. You can simply write conn dot. Okay, again, we need to
put it in the try catch. So this is how you can
close the connection. And then let's run it. I think Delete won't work now. I'll simply command because
Jane is already deleted. Okay, so I'll just keep this retrieval and let's run it to see if the
connection is getting closed. So Java application, and we can retrieve the values. This you are seeing as null
because if we go above, this is because of this one. We didn't comment it out. We're going to come into it. Okay. So this was all about the JDBC and how you can execute the different
queries like create, update, retrieve, and
delete using JDBC. Thank you for
watching this video. See you in the next lesson.
25. Use JDBC from JSP Demo: Hey guys, welcome
back to the course. Now in this video
we'll learn how you can use JDBC with that GSP. So we will go back
to our workspace, the previous workspace
which we were using, that is my workspace. Launch it. So this was the workspace
which we were using earlier. Now, we need to create a
new dynamic web project and see how we can
use JDBC with JSP. File. New. Then dynamic web project. Give it a name and give 11 to be JBBs. And we have the runtime here. So everything is there. So next and then next, generate the web
dot xml and finish. So let me close the files
which are already open. And this is our 11 to JASP JDBC. And we do not have any files in this because we are
used to create it. Now, let us do a quick
recap of our JDBC lessons. So we had to create a database. The database is already
created in my sequence. Now for the steps which we had, we need to load the driver, create connection, execute
query and close connection to. These are the steps
which we need to follow. And before that there is
a prerequisite that is, add my sequel connector
jar in-built, but let's fulfill our
prerequisite first. What we'll do is
we'll right-click. Go to Build Path,
configure belt path, module path, then
add external jazz. So remember we had already downloaded the my
secret connector. So we are going to add
it to our belt path. Now click on Apply
and Apply and Close. Our MySQL connector. Java is important. So the next step would be to
create that G is prophase. For that, right-click
on the project. Click New. And then J is PFA, going to name it
as index dot JSP. Click on Next. Finish. Now in this JSP file, we're going to create a form. So show. Student sum should be
our name for the title. Now next we need
to create a form. Before that, I will
use stage three. Right? Sure, student from okay. So what this form
is going to do, it is going to accept
an input variable, which should be the idea or
the role of the student. And based on that, it will show the student details
from method equal to host and action equal to show dot js. So it'd be creating this
shoulder t splitter. Now inside this will have input. Use a label. And third rule. So the user is going to enter
the role of the student. That we need an input of type. So input type equals text. Okay? He written name equal to okay. Now the next thing is we
need to submit the form. So input type equals submit value equal to show quickly user beer tag here. And also here. Okay, so our firm is ready. Next, we need to create this, so sure that JASP, then we'll write the rest
of the code for that again. Right-click on your
project, new ASP, JSP. Next, finish. Let me give the title. So title should be sure. Student. So here we will display the details of that
particular student who's roll will be the origin will
be submitted in this form. So we need to now open up triplet in order
to write our code. For that. Open this triplet. Know next. First of all, we need
to accept the rules. So rule equal to then decreased dot and
get fatter meter. Within this. Right? Now I
think we need to typecast it. So let's cast it. Cannot cause from string to int. Okay? Then we can use the
integer dot parse it. Because using this one, I think we can
convert from string. We have got the rule. Now for this role, we need to search in our database and find
out the student details. First of all, if you
remember the steps we had. So we need to, these
are the steps, so we need to load
the right driver, create connection, execute very end, close the connection. So let's follow those steps. So first of all
is loaded driver. For loading the driver, we need to write this
class dot for name. Say this, we need to
write the drivers of conn dot my dot JDBC. So this is how we
will load the driver. Next, what we have. Next. After loading the driver, we need to create the
connection, okay? So for creating that
connection, what we need, we need the username, password, and the Iwata
of that database. So let's begin with that username equal to, okay, next string, password. When do we have next? So for the URL again, string URL equal to then JDVC colon, my steeler colon slash slash
local host port number, which is 3306 colon. Students. If you remember
when we had created this d a database in MySQL. So it'll be using
this same database for this example as well. Next, we need to create
that connection. So for creating the
connection, connection, gone equal to then driver manager dot connection. And inside this we need to
give the username password. You want. This is how the
connection we've built. Now you can see there
are some errors which are coming up for
connection and driver manager. So if you remember in
our previous examples, we were importing the
java dot SQL from there we were importing
this connection class, so we need to do the
same thing here as well. So we need to import that. So for importing
inside this directive, you can input so you have to write page within this page to import equal to and then Java dot SQL dot star. Okay? So unto him put this, you can see everything is gone. Now, what do you need to
do is you need to create the statement, statement as T. Okay? So you need to write the statement statement
is still equal to. Then you need to write
Guan dot create statement. Okay? Conduct feed statement. Statement is really no way
to pass the query date. So for the fatty ready
to write our query, so write string equal to select star from students. Or you can write a rule
because we have the field as its rule equal to. And we can directly append
the role which we have enough room in this variable. Right? So the place ready
now we need to execute. Now you know, we need the
result set in order to accept the result equal to ST dot execute already within this
dinner tonight. So we have the result set iris, within which the details of
the student will be finished. Now, dot next. The next thing is we need to bring to the
student details, okay? So I will use this h4, h3 tag. And right student did. And then and rule. And then we need to open this. I think we can open
this expression tab. And then within that we can
write Iris dot get, getInt. And we didn't that s1
dot name of the field. Okay? And then you need
to close the p tag. Okay, so it is closed. Now let's see why we
are getting this one. So this is all complete. And next we need to
think that the stuff, so let's bring that knee and sit. There should be a string. So Raleigh's integers,
so we're using, but for the name and city should make it string name. Okay, So Control S. And I think we're done. Now. Let's run this and see. So right-click. And then until what? Choose the Tomcat server
and remove this 111. We just need 11 to finish. Okay. Yeah, it has that on it. Now, let's give the
role as one and sure. We are getting somewhere. Let's stick out what is there. On line 40, we have some metal. Let's go and check the
line for Jasper Apache, just for exception of
possessing shoulder, GSP. Let's, let's go and check
at this line number 20. Open your workspace. And snow. Line number 20, we
have connection, driver manager dot get
connection, username, password. So this one seems
fine because we also used it for our JDBC
example as well. Now let's check this username, password and URL. If
there is an issue. Username is root password
is rho, that's fine. String URL, JDBC colon, MySQL colon slash
slash local host. Then we give the port number. Okay, so instead of this
quadrant, we need slash. So let's save this. Now I will run it again. I think this will run no. So let's see. Next. Finish. Again. I
will give the rule. Sure. Okay. Maybe it's another letter. Let's see what is the error now. Again at line number 20, let's check from the console. You can check the issue, okay. So I will restore
the default view. So go to Window perspective. Okay, they said, Okay, it's showing some problems here. Now let's go to the console. Okay, the controllers gone. Now, let's right-click
and run again. We can see the issue that we are solving
the issues right here. Because it helps, it will actually help you when you
get this kind of issue. So nine number 20, again, there is one exception
occurred processing. So let's see the root
cause of the exception, which is Java dot SQL. Sql exception. No. So the driver
found for loop. Let's go back. We have JDBC, MySQL. Let's check if we have the
reference libraries or not. Yes, have them mice equal
radius. That's fine. Okay? Okay. Okay. So the reason is, if you remember last time
that the class name, I mean, the driver name has changed
for the new version. So it should be com
dot mysql dot c, j dot DBC dot driver. Because if we see
here, yeah, so calm. Mysql C, j dot JDBC. Insert. This will have the
drivers and all. Let's rename it and
check. Save this. Now, let us run it into the show. Again, we're getting
some issue. Let's check. So it's the exception same Java. So let exception, Java
sequence dot secret exception, no suitable driver
found for root. So what we'll do is we'll Search for this DDL, some troubleshooting steps which I'm showing you right now, which you can apply if you
face any kind of issue. Let's check for
the solution here. Glassdoor for name com dot
my sequel, JDBC driver. This forces the driver
transistor itself so the java knows how to handle the
database connection. Yeah, we are already
running this. You have to load
the JDBC driver. So how can we load that? We have the URL and then
load and password, fine. Driver manager get
connection, you are, okay. Okay, So let's try
giving the URL first. I think that will
resolve or issue. So I will simply
Control X, Control V. Then we have URL,
username and password. So this sequence also matters. So remember that
Let's save this. But an S. Then on silver. Finish one. Sure. You'll see the recent
one, John, New York. Okay. So these were some
troubleshooting steps which I wanted to show you because I could have directly written the Warren and just
run it and show you. But there are certain
things we need to take care while
writing the code. And when we're in a flow, we might miss certain things. In that case, how can you
come back and how can you resolve those
particular issues? That is what we need
to do as a programmer. When you face any kind of issue, don't give up on that. They either look into the issue, what can go wrong. You can take the help
of the Internet and see what is the issue and
how you can resolve that. So I think we have
resolved the issue and we have now our
desired output. That is, we have
the student data. So in this way from the JSP
also you can connect to JDBC, can run the SQL
queries from here. I hope this video was
informative and I am sure it will help you in the troubleshooting
steps as well. So thank you for watching this video and stay
tuned to the course.
26. JSP Tags: Hey guys, welcome
back to the course. So in the last video we had seen about how we can connect
to JDBC using JASP. So in this video, we'll go ahead with some
other concepts of JASP. So it will be looking into the basic tags which
are used in JASP. I think we're already using this script tag and also
this expression tax, but there are other
tags as well. In the JSP we have also this
one which is directed path. So I'll show you about
the different tags which we have in GSP. For that. Create a new dynamic web
project and give it a name, as they should be
R11 three JSP tanks. Now click on Next and Finish. We have a new project here. I'll simply close the
previous open phase. Now, we won't have any JSP files inside this
epsilon newly created projects. So we'll quickly
clear to JSP file. Right-click new and
JSP file index.js. Click on Finish. Okay, so I'll change
the title to JSP x. First of all, we'll learn about
the expansion tank, okay? So how we use the
expression tank, let me use H3 x relation. Okay? So how the expression tag
looks, looks like this. What I'll do is I'll
use the expression tag. Okay? Within quotes, I will
write this expression. And I also mentioned
how it looks. So what is the purpose
of this expression pack? The purpose of it
is to display or print the things on
the screen in JASP. So generally we use
out dot print LN. We can use that in
those triplet as well. But this expression, using this, we can directly, well print the string or anything
which we give here. We could have also printed Les of a variable or
Java variable as well. So this is for the
expression tag. I'll also show you
how you can also print a Java variable. So for that, we need
to use a script. Let me show you what the script
let as well in some time. So let's say x equal to ten. And again, we'll use
this, print this x. Let's see. So the output
should be disease, expression tech and ten. Let's see. So right-click, but
then on server, then select this over. I need to remove the
previous one because otherwise it will also
be there in the summer. We move to 11 to
finish legal key. They start the
server. Wait for it. Okay? So you can see expression tag, these are header and
this is iteration 1010. So this has been printed. Okay, so using this
expression tag, we can print on our screen. The next thing is triplet. Triplet, which you can see here. This is a script. Let anything rewrite between this and this is going
to be our scatterplot. In saying this triplet, we can write our logic, our Java code, and everything inside this particular section. The next thing which
comes up meant, okay, So the command looks like this. This is so anything you want to comment out
from your JSP file, or you want to add some
custom commands in order to define the code
which you are writing. Then in that case, you
can use this command. Then we have, so we have
expression DAG script tag. And the fourth one
is declination tank. So let's see how we can
use that declaration tag. We can do it. So let me write a comment. First. Find the law. Thank okay. So we're going to write
the declaration tag. Know how like this. In this script, we can
declare the values. But this declaration
tag also helps us in declaring some values. So late public int
y equal to 40. Okay? Similarly, we
can bend this way. Let's run this and
see if we can see the value of y should be 40. No non silver. Next finish. Yes, so forth. T is also printed. This is how you can also use the declaration
tag for declaring any variable in
your Java JSP file. Now next, we have
the directive tech. So this one is actually
the directive tech. But per cent. So what it does, it has this speech directive. These are called directives. And then we can define some attributes
like language equal to Java, content, type, etc. You can also use the directive tech to
import certain things. I'll show you that as well. Okay. Let's write another command. Find below directive. So this is how we write
the directive tag. Now we can write page this is the directive
which we're using. And we can write import equal to suppose Java util dot date. We're going to import
this particular java.util package and we're going to use it so we can use
a script right now. So I create an object
for this date. Okay? And now we can
simply print it. So dead dot two string. We can simply print
it like this as well. I'll quickly it
was a BR tag here. We see it in a separate
line. I mean, the next lane. What it is showing, it's not displaying data. Cannot be resolved to attain. This shouldn't come. Share income. Let's run it once. I mean, then we will get a total exception or edit so
that we can work on that. Let's see. Okay. So it was not an error. I mean, we're getting the deed. So this is the date. This is how we can import the java packages using
the directive tank. Okay? There is one more use
for this directive tab. That is, we can include other
JSP files inside this file. Love weekly show
you that as well. So let me create another GSP phi nematodes header dot GSP. Next, finish. We want this, whatever
will be inside this two, we end up bulk of our JASP
pH to how we can do that. I'll just quickly
write some text. So this is a header. Okay, save this. Now, head back to
this index or GSP. Here. Above everything,
I'll include that the direct div tag
name and write include the state won't
be using the pitch, but include, included
another director. And we need to
mention the beach. H equal to hinder dot js. Now save this. It's
showing some short. Let's check. Okay, so it shouldn't have
the name Beach butterfly. Okay. So let's use fine. Let's check if this
is also an issue. Yes. So you need to
include this file. Now. Let's then S until Next. Finish. And yes, you can see
this is a header. But can you find that
particular texts in index.php know it is inside
this header dot GSP. Since we're including
this JSON file inside this index.js index.php. That is why we're
able to see this H1, which is, this is a header. So I hope now you know about the different tags
which we can use in JASP. You can play around with them, do some hands-on with this tax. So let me quickly recap. We have different texts. Number one, expression
tech than script, tag, command tech, declaration
tech and directive tech. You can play around with
this tax and see Lake. You can try out
different things and run it and see the output. So thank you for
watching this video. Stay tuned to the course.
27. Error handling in JSP: Hey guys, welcome
back to the course. So in the previous video, you have seen the JSP tax. Now in this video,
we'll look into how you can handle
exceptions in JASP. So for that, we'll create
a new web project. So new dynamic web
project, give it a name. So 11 for JASP exception. Okay. Click on Next and Next and generate a web dot XML
descriptor and finish. Okay? Now next thing what
we need to do is we need to open this particular project and close all the open fights. Okay, now we need to create a new JSP fights, new JSP file. Give it a name, index dot js. Next finish. Okay, now let us create
a form for where we'll be submitting a request and we will be invoking some edits. And while there are
arrows I invoke, then we'll write our GSP
where we'll handle that. Let's name it does divide
two numbers or whatever. I'm going to create a form
action equal to divide. Jsp. And methods
should be most insane. This will have two input fields. So I'll write the
liberal entered first number and then
write the input tag. Input type equal to text, name, equal to num one. This done. Now copy this two-part. We're taking here as well. Okay, and pasted. Now the place first
with second num one. Num two. Again a beard. Now we need to write
our submit button. Input type equals submit, and the value equal
to the right. Okay? Form is ready. We'll simply save this. Now, the action is
width divide the GSP. So let's quickly
create divide dot GSP. So right-click and new JSP file. Divide dot GSP. Click on Next. Finish. Now, let me
open a scatterplot. First of all, we need to
retrieve the form data. So int num one equal to
request dot get pedometer. No, one is the name of
the parameter. Okay? Now again, we need to
convert the string to int integer dark bars n. Okay? So we have our num one. Next, we need to also have
the num to replace num one, num two, and then name also. Okay? So now we have both the numbers when
you divide it, right? So we will write quotient. We can also write the result
is much better that way. Result equal to
num one, num two. This is going to perform that
division operation for us. Then we need to
print the result. So this is simple. Now that we're taking two numbers as input
and we add them, getting the result, we
just by dividing them. Now, what error can
occur in this case? Some edit meeting
exception can occur lake. If num two equal to 0. So anything divided by 0
will throw an exception. So how can we handle
this situation? So in that case, we need to show a message to the user regarding that
there is an error. For that, we need to
define it either page. How can we do that? Again, using the
directive beach. Beach equal to dot g is okay. So basically we are saying that if you encounter
any kind of error, this is the place where you
need to go to this Edit. Notice. Now where
is this editor, GSP, we need to create that. So right-click new JSP file. Next. Finish. This is all red dot GSP. Now how this page will
understand that I'm edit page. For that, we will have
another directive which is is it beach equal to this
will ensure that the, that it is a little
bit what it is saying. Jsp. Okay, so we forgot a directive if the
directory shouldn't be there. So this page is important
and this is an attribute. Okay? Now next, what we need to do is
we need to show data. Exception dot, get message. So this will redirect to the editor page and
show that message to us. So let's run this and
see for this working. But unless run on server, Tomcat removed the
previous example. And click on Finish. Restart the server. Okay, first number,
second number. So 63, answer should be yes, we have to, again, go back. Remove this divide. We're back. Now, let's say five
divided by C2. Let's check. It's giving us an edit. Let's see. In lengthy column 22, there is some error. So let's see what this era. Jasp, line three. Yeah, is it a page? Should it be in Saint coats? Let me check. I think this can
resolve or issue. So let's see the next next. Finish. Again, what will
lose six by 0, right? Yeah. So we're getting the
message that divide by 0. So from where we're
getting this, we're getting this from
the edit dot js window. You can see the write.csv, but divide or JSP is
actually internally redirecting to error that
they span from there, we're getting this
message. Okay? So this is how you can do the error handling,
exception handling. In JASP, you can create
a new error page and you can define what are the
areas you want to handle. And in the page where you will know that it is going to throw
some exceptions or errors. There. You mentioned
the beach to which it needs to differ
in case of any edits. So this is how the error or exception
handling works in JSP. Thank you for
watching this video. See you in the next lesson.
28. Project Introduction: Hey guys, welcome
back to the course. So now we'll create our
JASP project for that. Go to File, click on New, and select dynamic web project. I'm going to name it as 115. This is going to be our final
project, so JSP project. Okay? Notice that n time
everything is fine. Now click on Next, click on Next, generate
the web dot xml, and click on Finish. So our 115 JSP
project is created. I will quickly close all
the files which are open, and I will open this one. Now. First of all, we need to
create a user's login page. Okay, so what we're
basically going to create here is we're going to create a user login
page where users can login will also
have an advantage where admins can
login and basically whatever reduce the admin
routes the user can watch them. This is the project
we're going to do. Let's get started with that. First of all, we need to
create a new JSP file for the user login to JASP file. Now, right, index dot JSP. Click on Next and Finish. So our index dot js p3. Now in order to read the form, let's take help of Bootstrap. Okay, so we will be
using Bootstrap here. Now, let's go to, Let's go to Bootstrap. Forms. In Bootstrap, we have
here, click that. Now if you scroll down, there are different
types of forms here you can see email address
and password. So why you're using this? Because we don't need to write the extra code
which we're writing. We can simply use the
Bootstrap forms and use it in our web project. So I'm going to
simply copy this one, this email and password, which we can easily use
it for, sign-up, sign-in. Let's go back to our project. There is give a heading, so H one user login. Okay? And then we will
simply paste the code. So this going to be alpha. Now, there are certain
classes which you can see from control,
from texts, etc. For that we need to
obviously get Bootstrap CDN. So let's do that. And just search
for Bootstrap CDN. Now, you need to go to
this getbootstrap.com. And then if you scroll down, so one way is we can install the package
manager for Bootstrap. Other ways, like we need
to include it via CDF. We get into this residents. So I'll just copy
this for the CSS. First of all, copy for
the CSS and paste it. Paste it inside the head. So this is how you can best
for the CSS Bootstrap, CSS. And next we need the CDN for the Bootstrap JavaScript bundle for the Bootstrap JavaScript
elegant copy this. Go back to our workspace
and paste it in index.js. We have the CSS and JavaScript
CDNs for Bootstrap. Now save this. Let's run it and see if we can get some output. So right-click. Then S, then until
they're Tomcat. They move the 11
for short run 115, so the service starting. Okay. So we have the user login and this
is how it is coming. There is another way to
make it more beautiful. What do we can do is we
can use some containers. Okay? So let's do that. So we'll be using container. So div class equals container. Okay? So we need to close
the div tag and the end. Cut it from here. And after form, I will
paste the div tag. The next thing is we
need to write def. And then class should be. And we need to put this
login inside though. Okay. Now let's see how
our page looks now. So Renee's run on solar. Next. Finish. Okay, See, now this
is how it looks. It has got some indentation on the left and
the right as well. So I think this view is
much better than this one. Okay? So I just close this. So this is how I would say
no sign-in form will look now email address we have okay. And then we have password checked me out as
not required for us, so I will remove this one. So let's go back and
remove the tick me out. The slip. We can now remove this whole dips so that we do not have
the check boxes. Control-s. Let's go back and refresh. Yeah. So it has gone. So that check me out is gone. We have our email address
and password where the user can login login
page for the user. In the next video,
we'll see how we can create the user database. And we can add some users there. And then we can check
the login functionality. Thank you for
watching this video. See you in the next lesson.
29. Project - Create DAO: Hey guys, welcome
back to the course. So now in this video, we'll be creating
the users database. So for that, we need to run some radius in our
MySQL command line. So first of all,
we need to create a database and then
use the database. And within that, we can
create our user's table, which will have the e-mail and the user name and
password as the feet. Okay, So let us do that. We will go to my sequel. Command line is our password. One-by-one, run these commands. So create database. Let's go there and
just paste it down. Database is created. Next we need to
use the database. So use JSP project DB. Database changed. Now we need to
create this table. Simply copy. So
create table users. You imagine this
the primary key. You named, user password. So these are the three fields we have for our table users. Now press enter. Our table is also created. We can look into the
description of the tables, so DAC users, and this
is how our table looks. Okay? So we have your name, password, and this
is the primary key, and these are the vectors. Now, we need to insert some
data into the table so that we can use it to test
our login functionality. So inserting two
students values. Let's add some values. So email will be
user one and period. Gmail.com. Username should be user1. And the password that
does give us 1234. Okay, Let us run this. So I'll simply copy
this, paste it to. So there's some issue. Students, sorry, this should
be users and not students. So users. So we have been doing so
many examples, right? So sometime it happens, one row is affected. Let's see. So select
star from users. And we have this user one. Now let us go back
to our workspace. Now here, we need to
create the entity class. So for that, I'll go
to the Java main file. Now create a new package, Guam dot, draw object dot. And this will have our entities. Okay, click on Finish. Now we need to add
Java class here. So click on Java class. And then namely this user. Okay? I'll create a constructor from the superclass and
just click on Finish. So I would use your
classes ready. Inside that, we will
create a string. You email, string, name, string, you PWD, which is odd. Let us set constructor. So clear, slick on the source and then generate
constructor using fields. Okay? Check all the fields and the congenital.
So we have our Parametrized constructor. Next we need to have some
getters and setters. Again go to source, generate getters and setters. Okay, now click on January. We have our getters and setters. The last thing what
we can do is we can also generate
a toString method. So I'll also do that. Click on Generate.
Users entity is ready. Now, how can we fetch the user
details from the database? For that, we would need
some Douglas's, right? So for that, click
on the SIC mean non-Java folder and
we need to create another package,
com dot project. Don't tell what is tau now
stands for data access object. This DAO will help us
to access our data. So click on Finish. This does create a
new Java class user. Okay. Click on Finish. Now, in order to
search any data from the database we would need. Connector will need a class which will help us to
connect to our database. Inside this down here
I'm going to define a JDBC connect class. So go to new class, name it as JDBC connect. And click on Finish. If you remember, in order
to execute any kind of JDBC programs or
JDBC connections, we need to have the
my sequel, right? So MySQL connected jar is
needed for that. Right-click. Go to Build Path,
configure Build Path. And in the module Build Path, click on Add External gyres. We have my secret connector jazz selected, and click on Open. Click on Apply, and
Apply and Close. Now, inside this JDBC connect, we need to have a method, public connection, and then cleared connection. And let us define the
connection object first. So connection. Now we need to import
the connection class. So imported from
Java dot sequence. Create connection.
Fine. Now inside this, if you remember, what were the steps to create a connection to our database that is loaded driver and
create connection. So let's do that. Load the driver. For the loading a driver we need class
dot foreign name. And inside this com dot my sequel, JDBC dot train. Okay, let's see
what it is saying. It should be within try-catch, so we can easily
add the try-catch. So we have loaded our driver. In order to resolve this era, which asks us to add
a return statement, I will quickly add a return
statement, return one. Since we return an object
of this connection. Now after loading, we need
to create the connection. So for creating the
connection we need three parameters,
username and password. So let us first define
the word string. Equal to then JDBC colon, my sequence colon slash
slash local host. And then the port 3306 slash
and name of our database. So what is the name
of our database? Let's cross-check. The name of our database
is JSP project. Simply copy this
and paste it here. What do you add a
listener ready? Next we have the username. So a string username
equal to string password. Now we need to create the connection for
that. We need to write. Gone. So first
let's define this. Coin is already different, so
colon equal to then driver, manager dot get connection, URL, username, password. Let's also import. This should be within try-catch. It is already within try-catch, but it's one to add
the sequel exception. So let us add the sequel
exemption as well. Connection, JDBC connection
class is ready. Save this. And now we'll go
to our users down. Okay, so what do we
need to do here? We need to fetch the user data. For that will again
create a method public. And it should be user because
the type should we use it. So really use this user class
and then get user email ID, which is the primary key in
our case, for the users. So string. You meant. What we'll do is in the
beginning of the class, we will create an object
of the JDBC connect. So let's do that. We can do it inside
our constructor. So let's generate a constructor. Okay? So we do not have the fields. So we can generate a constructor
from the superclass. Now inside this, we can call the JDBC connect and then JC equal to JD VC Connect. Okay? Now we can define
a connection class here. An object of this. What does it say? To find? Okay? No, I think insert all for
doing inside the constructor. We can directly do
it inside this. I think this will
be much easier. So we can get rid of the constructor because
every time otherwise we need to call the
constructor bytes and this, we need to import the,
what is it saying? Okay, we need the braces. Okay? Now we can take
corn equal to JC dot. Create an action. This will create a
connection for us. Now next we need to
face the user details. So for that, we need
to resolve this user. So import user from Conduct
project dot entities. What it is saying, we
need a return type, we'll do it eventually. Now next, we need
to write the ferry. So string equal, select star from users. Read. You. Equal to. So this is a dynamic course credit for
that we need to repair. So prepared statement b is equal to one dot
prepare statement. And I'm going to
provide the Fed. Now we need to
import the text it. What is it saying? It should be within
try-catch, okay, put it inside a try catch. Okay? Now we need to set
the dynamic values. So for that P is not set string. One, coma. You emit it. Now whatever
result we'll get back, we'll get back inside
this result set equal to this dot execute. Okay? Now, also important
this result set. Now if artists dot
next, that is, if we are not honest, we have named this set, so set dot next. So if we get back
some other time, then we will assign
it to our user. Okay, so we'll create
a user object here. New user. We'll use the sectors
inside this user dot set. And then within that said you
even we need to send dot, get string and the index or the column names, so UE. Okay? Similarly, we can fetch
the username and password. You name and you PWD. Okay? No, we will simply
return the user. Let's save this. Our user data is ready. Okay? Next what we'll do is we'll
create welcomed or JASP file. And inside that, we
will do the login. And after login, we'll
call this user Dao. And then we'll fix the
user details and show it. Thank you for
watching this video. See you in the next lesson.
30. Project - Login Module: Hey guys, welcome
back to the course. In this video, we'll
be creating our class. So for that, we'll
do Java right-click. And let's create a
new package name or test com dot project. This will be our controller. From here. We will have the
servlet classes. So for that, right-click, then select, give
it a name login. So in this login Telnet, we'll write the
logic for our login. Okay, so let's click on Next. Next and we need to post, so it is checked there. We don't need to get okay. Let's finish. Okay. Let's remove this
instructor and on. Okay, we have the post method. Let's go to our index dot PHP. So here we need to
write action equal to then slash login and method equal to post. Okay? So whatever username
and password we enter it as going to this login. Now, let us set the name
for our input ID we have. We also need to set the name. Okay, so the name is
Naomi, call to you. For the password again, we need to set the name, name equal to u PWD. Okay, save this. Now let us go back to our login. So let it is mapped to
this slash login URL. Now we need to fetch
the parameters, right? So for that string, you email equal to request. Get better. And we didn't let you imagine. Okay? And next will be string. You PWD equal to the request dot
fan I'm with you. Okay? So we have
username and password. So what do we need
to do with this? We need to validate if the
username and password, the users and the
correct or not. So for that we'll use our
user doubtless, use a dao. Create an object. You use a tone. And we will import
this user down. We should, we should take our user entity class. And we need to use a dao. Insane this, we need
to pass the image. This will return
the user object, really important
user object from this conduct Project dot
entities which we have cleared. Okay. Now next, what we need is we need to verify if the password renter
was correct or not. If user password not equal to null. So first of all, if
there is no such USA, then we'll get the null. Otherwise, if it is not null, then check if user
dot get password dot equals you pass UP them. So if both conditions are true. Then the user has entered
correct username and password. And if the password
doesn't match, we will simply write else part. And also if the user doesn't
exist, we'll also write, and now let's first see what we need to write if the user image and
the user password. For that, we need to
first have HTTP session. At HTTP session,
session equal to request dot get import HTTP session. Okay? Now what we need
to do is we need to set some session attributes. So session dot set attribute. You email. Since this is our primary key, so I'm going to set
it, so you email. And we need to also set
the user's session. Set attribute user. And this should be okay. What we need to do is we need to pass it to our welcome page. Response dot send the SP. Okay. Where is this? Welcome dot JSP. Create that. So let us write
this part as well if the password doesn't match. So session dot set attribute PWD. Okay? So it should have a message. Please. Enter password. Okay? And again, this
bond send redirect. Now this time we're not going
to redirect it to welcome rather than index.js
p. Similarly, we'll copy this this else part. If the user doesn't exist, then send a generic edit. User. Does not. We're going to redact it
back to index.js be okay. No, Logan is ready. Next, we need that
welcomed or JSP, right? So for welcomed, not JSP. Right-click new JSP file. Welcome. Jsp. Next, finish. Instead, welcome dot JSP. Let's rename it as well. You can also do that
for our index page. Should name it as login. Okay. Now let's go back
to welcome here. When it open unscripted. First of all, we need to see if there was any errors
or we have a response. So if session door to get attribute in it, not equal to null. Okay? So in that case we
need to just use this triplet Auto week and also you don't want
come to welcome page. Editor will come to index page. Use this in the index, discard this, and come here. And they stirred, create another div. Nine centers will
write this one. Okay? So if we get an error, in that case, we need to do. So. Let's use Bootstrap
for that as well. So in Bootstrap, you
can find this alerts. So there are different kinds of alerts and we're using
this danger one. So let's check out. This is the one. So let us go back
to our workspace. I'll simply, what
I'll do is I will end this triplet here. And I will paste it to open
Nazca plate here. Okay? Now, instead of
this as a danger, Ivan, display the message, okay. This is what will be displayed. There is another
condition we can use. Let me show you. So simply copy this, paste it. So the next condition I'll write else-if the insert,
edit, edit, PWD. So in that case we need to print our error
handling is done. Now, let us go to
our welcome page. And what we can do is we
can open a script blood. Now here. If session dart get attribute, and we get you email, that is not equal to null. That means we have a response
inside this, right, users, user, user session
dot get attribute. And then now it is showing that user
cannot be resolved for that we do import user for that. Simply come here, use this
directive back and write import equal to com dot dot dot. This will be resolved. We need to cast it to user. Just right. And all data is alkaline. Now what we can do is we can
simply show welcome message. So for net flow stuff and use the expression welcome. And we can use an H1 tag space and then use a kick. So pinup script, Let's save this. Now let's run it and see if we're getting our
desired output. So right-click run
S and then un-solo. Next. Finished. He started his own
username and password. Let's enter some wrong
username and c. Abc gmail.com. And password will be 1234. There's the password I'm
entering. Let's submit. Okay, it's showing slash login
is not a vulnerable. Okay? So instead of slash login, we can use only
lumen in the form. Use on little login, because if you slash it
is not recognizing it. So let's go back 1234. Okay, we need to,
I think the renin, so because we have made
a change, let's do that. Again. Let's try ABC. 1234. Summit. User does not exist. So we're getting the right
error because obviously abc, gmail.com doesn't exist. Okay? So one thing we need to do is we need to remove
the session attribute. Because every time, because
if this t is everything, we'll see the same edits. So what we'll do is after
this error is shown, we will simply session
dot remove attribute. Okay? Similarly, we'll do it for our enter the
password as well. Save this, run it again. I know it's a little tedious to run every time on the solar. But this ensures that we
get the right result. Now, let's enter
a wrong password, okay, so we have user
one at gmail.com, which is our correct user. Now, let us enter the
password is 1234. Let me show you 1234. Let's submit no user
does not exist, right? Because we're already
giving valid answer. Let's take user
one at gmail.com. Let's check our four days. Well, let's go to our login. Dot Java. Okay, User dot get fast-forward, not equal to null. If none, then user
does not exist. So maybe it isn't getting null. That is why it is
showing like that. Still we're getting an error. That's good. It'll go back. Let's proceed with our next. If we refresh, it will go away. Now, let's try with
gmail.com. We didn't give. So let's try with
gmail.com and 1234. Yeah, user doesn't exist. Now, let's give it user one at gmail.com and it says 1234, which is our username
and password. If we go back, we can see user one at gmail.com and
pieces 12345 summit. We're still getting
user does not exist. Y. Let's see. I think it is, the cash
is not clearing itself. So let us go to Inspect. We can manually clear it
and I'll also show you how you can clear it
from the coordinates. So let us go to Application. And then cookies. Here we have it. The session attribute. Just click on
Delete, refresh it. Now, right, user one entity, gmail.com and the *** 1234. That's correct. Now, we are again, getting user does not
exist. Why is it? So let us find out the issue. So in the user, I mean the login dot Java, we have this set attribute
user, user. Okay? We're fetching it from user
doubt stick user don't know. Setstring. Okay, fine. He was a dot set, UML, UML. Okay, so here we need to
set the username and email. You name. This should
be you PWD. Save this. Now, let's run it. Please start this over. Now use admin. Is this 1234, which is our password. Now submit showing
where user one. Okay? So be careful while
setting the attributes. Because since we
copied it from here, so it went from. Now when we have the
correct password, it is giving us the user
one. If we go back. Now one more thing. Yeah, if we go back
and write 1234. So see, this is the
password we're rating. Let's see. Now I just shrink
enter correct password. We were not getting that
we're only getting wrong. User does not exist straight. So I think we are now pretty
clear with our login. So p is 1234. So yes, we are locked. So our login is working
perfectly fine. In the next video,
we'll work with our next part of the project. Thank you for
watching this video. See you in the next lesson.
31. Project - Logout Module Part 1: Hey guys, welcome
back to the course. So now we have created the login dot Java and we have
seen how we can login. Now. Next we'll be seeing
how you can log out. So we have come to
this welcome, not GSP. In welcomed or JASP. We need to in a modified this page or it will bet we can use
Bootstrap for that. And we'll use a nav bar
where we'll have the login, but the logout button
for that go to Chrome. And we can search for navbar. We can see when nav bar here. You can choose as per your wish. I mean, you can scroll down and see what kind of
navbars are present. Forms in the nav bar, etc. There are buttons which
you can also place on the napa, text, et cetera. Now let us go up and choose
our Napa. Choose this one. Copy. Go back. My workspace and paste. The NAFLD is here. We do not need all these things. I mean data, links, decibel forms, etc,
drop-down menus. So we're going to
get rid of them. Okay, let's get rid
of the dropdown. So let's get rid of this decent. Rid of this form. We want it to be simple
where we can have our login. So this is whom we do not need the link here
instead of this nav, but I think we can use it here. Let me show you as simply
card this from here. I'll paste it here. And this, and this from here. And paste it here. And instead of this H1, now I'm going to that I didn't
say this one. This one. And paste it. Next. What we have, we have button. Okay. We want to use this button here. We'll see what we
can do with this. And next we have the way
even tax should be closed. That's removed,
it's just pieces. This div tag is fine and
we have the nav tag. Okay, let's save this. And now let's see how
it looks. Right-click. Then on silver. It does give you the 11234. This is how it looks. Now, you can see it isn't a distorted form because we
do not have the Bootstrap, CSS, css, and JavaScript CDNs. Okay, so let's go
back and add them. I mean, as a developer, it is very important for
you to understand like, what is the issue, why it, it's not like a big deal
to get some adults. But as a developer, you need to understand what is the error and you need to take proper steps in order
to resolve them. This comes with practice. Do not worry if you cannot
identify right now. When you keep practicing, this will come
automatically to you. Now we have added the CSS and
JavaScript Bootstrap CDN. Now let's see. If we go to console. Oh, actually it should
reload, but it hasn't. So I'm going to run it again. Give the credit and shoots. Welcome user1 and whom? Stuttering speech. Okay. Now, we cannot see any indentation on the sides will use a container for that. Let's go back and insert the Florida stiff plus CO2 and the div tag. Save it. Now instead of light, we can also use that dark thing. So if you see here,
it's navbar light. If we use dark, Let's see what we can see. Some background noise. Let's see if we do things
the adapting what we did. So right-click. Then this next finish, and then give the credentials. Okay. So it's showing
enough black. Okay, I think this is
looking more good. Welcome user one is the home screen and we
need a logo, the button. Go back to our editor. Now, we need to create a button. So for the button, let's see Lake, if we
have any option here, I want to get it. So let's go here and search for button buttons. You can see different
types of buttons here as choose the dark one, since we're using the dark mode. So this is the button
which is used. Let's simply copy this. Now go back in your workspace. And after the def, place a tail. Okay. No, save this. Let's see if it is reflecting. Refresh. Yeah, it's reflecting. Let's give it a name so it
should be Logo, not dark. Now, let's go back
and check again. Refresh. Yeah, we have logo. Now we need to add this functionality
for this logo to what we can do is let's go back. We can create a form here. Form, action equal to Logo, and method equal to post. Let's end the form
here of the button. Now instead of a button, let's make it input. Input type equal to submit. And let's remove this and write value equal to lock those this, Let's save it and see if it
is reflecting the fresh. Yes, there is no change. Now, let us write out. Logo, functionally D. So for that, we're going
to create a logo dot Java, so v. So let's click on New. So many sublet. You name it logo. Next, next, and we need to post will do the do get, finish. Our logo. Remove this. And also this coming In this logo is
basically we need to remove the session attributes
you email and user. And we need to be directed to the index.html After Logout. So how we can do that? Let's check out after we get the submission of the form
from welcomed dot JASP. So after after the submission of the form of welcome dot
JSP is done from here. And we get a post
request to this logout, which is the servlet. We come here and this
is the deposit method. Here, we need to
perform our activity. So first of all, we need to set the
issue to be session ID attribute equal to session, then equal to request,
dot get session. Okay? Import HTTP session. Now we need to remove
certain attributes. For that Session. Remove attribute
attributes, you e-mail. I'll simply copy this. The next one was user. So these were the two
session attributes which indicated that
the user has logged in. So we'll remove
those attributes. What we'll do is set a new
attribute called logout. And we'll set it to true. Okay? Now after this will be direct response dot
send, redirect. Which location index.js be. Okay, Let's save this and see forward logout functionality
is working or not. But before that in
the index.js p. Let's see. Yeah, this looks good. I think I just wanted to
do no. Let's run this. So right-click runners run, so choose us over
Next and Finish. Okay, so let's login first. So our cells use a one. And did it gmail.com and
our password is 1234. And we're logged in. Now, let's
see some moment of truth. Let's save the logo box. Yes, It tastes. Okay. So we have come back to
the index or JC page. Now, there is one
more element to this. What if we click on
the back button? Does it work or not? If we click back, again, we can look, get logged in. But ideally the shooting
happened, right? So let's fix this. If we go back in the
welcome, Doug, GSP. What we'll do is
we will Use check. Okay, so how can we use
the check? Let's see. If session contents, user element and that
is not equal to null, then we're doing this. Now what I will do is I
will remove this from here and move it to
the end of the day. Or you can also move it
to the end of the name. Okay? So this part will only be there
if you image is not null. But in case of No Logo to
feel remember what you meant was there was no human
we add remove it. Now if somebody wants to
access this even after logo. So what we can do is
we can check after this session dot get actually viewed logo. Okay? So if Session.get
her to put log out equal to, equal to true. If logo is true, Let's see what it is showing. Cannot define object as Boolean. Okay, No worries. Then we'll just do not
equate to this view. So this will also work. So if this is there, then we need to simply
send a redirect. Response. Dots sync, data, index dot js. Be. Seeing this. Now let us run it and see. No non server needs to finish. Let's login first. Login, logout. Now. Now let us go back. It is still coming up. Let's check out my so I think this because
of the previous sessions, what we'll do is we'll
delete all the session. I will go to this page. Now let's check. Logo. Mic is coming. So let us make some more changes so that we can remove it. In the index.js, be
this coming here. And if we click on back, so welcome dot GSP. So let us put this condition at fullest so that whenever
this is called, we will simply redirect first. So we'll put this
as if this is okay. So if this is not null, then we'll send a redirect. Let's check if this works. And it's not going
to the welcome page, we need to clear all
the cash and cookies. Because sometimes if the session attribute
is still there, we won't be able to
perform all activities. Okay? So we can now log
in. Now let's logo. Okay. If we click on back,
again, we're getting this. I think this is because the user attribute is
still there in our cache. If the attribute is still there in our cache, we cannot logo. So let's see how we
can remove them.
32. Project - Logout Module Part 2: So for removing the session
attributes from the cache, we can use this
response dot set header and Cache-Control know so, okay, so let me copy this. So what we'll do is
we'll paste this and our welcome dot GSP. Okay? And also I think
we can do logos. So we will use this cache
control non store to logout S1. Okay, we'll make another
check in our login dot Java. There also. We will set this on the top. I will send this one. Okay? And in the Logan also we can
set if the logo is true, then we need to redirect. So the login itself, if after the declaration of the session attributes and
just remove this from here. I don't know. Let me put this declaration
of the session and walk. And do if check if Session dot get attribute, then logos is not equal to null. So log of this present, then we'll send a
redirect response. Send the direct index dot js. So we have made two checkpoints
in Logan and wanting. Welcome dot GSP. Now let's see if this works. So I will close the browser
and that he's checked. So the next one on silver. Next finish. The stirred the user one at gmail.com. Okay, if the password
is 1234, this is done. Now we'll do log out. Okay, back. The back is not working now. I'm clicking on the back end. It is not taking us
to the welcome page. So now it is working fine. So one more small
change we need to do. Otherwise if we tried to
login also at one works. Now if I try to login, it won't work. Yeah. Okay. This is because the
logo is still there. So now what you can do is
you can go to index.js P and we need to do a check. Okay? So what check we can do? Else-if session get attribute not equal to null, then we can remove this logo. So let's remove it
Session dot attribute. Okay, so now this will
not prevent us to go to the welcome page now
in the welcome video. So we need to do another check. So here we can do else-if Session.get attribute UML equal to, equal to null, then we can again door response
dot redirect to index. So these are just
to make sure that the Back button to not
mess up with the code. So I'll just close this. Let's relaunch it. And let's see if it works or we need to put some
more validations. Launched this one
today, gmail.com. Password is 1234. Yeah. No Logo. Back. Not working. If it's working. So the load function it is walking into and thank you
for watching this video. See you in the next lesson.
33. Project - Home Page content: Hey guys, welcome
back to the course. So in this video we'll be
creating our video's database. So let me show you. So we need to create the videos table
inside our database, which is JSP project TB. When you do create this video stable where we'll have
the following fields, which are VI, VII, title, and feed URL. What it is going to
do is we're going to insert a video within
the particular table. And we can insert
multiple videos as well. But for demo, I'm
inserting only one. And what we're going to do, we're going to fetch the
radio details from our users. When the user's login
in the welcome page, they'll be able to
see this fabulous. Okay, so let's get
started with it. Then we will simply open
our my sequel command line. Enter the password. Now here. First of all, we need
to use our database. So use JASP, project DB, database change now in
to create the table. Create table. The name
of the table, videos. The fields which will
have is we underscore ID, integer five and
then primary key. So VAD will be our primary key. Next we have v underscore title. Okay, we should enter the
title of the video here, and I'm giving their care 20. Next we have, we underscore URL. The URL of the video
will be given. So this is the overall
structure for our presenter. Table is created the
C radios. Let's see. So this is how our table looks. I'll simply copy this for our reference
and paste it here. So this is how our
videos table looks. Now next we need to
insert some data into it. So I will copy this. We can paste it here. Insert into videos values. The VAD will be 101, and the title is Learn HTML. And this is the URL. So press Enter. Now you can run a select query to see
if it is there are not. So select star from videos. And you can see the
video and trees there. Now next we'll go back
to our Eclipse ID. Now here in our JASP project will be creating new classes
and new entity classes. Okay? So go to the entity class. We already have a
user Java here. Right-click on the
entity package and go create a new Java class. Give it a name, so I'm
going to name it as video. Okay. Check this constructor from superclass and click on Finish. Okay, let's go to
this video here. We'll have three attributes, which is number one
is we underscore id. Next one is string,
the underscore title. And the third one is
string underscore. You added. These are the
three parameters will have. Now, let's gender the
parametrized constructor. So generate constructor
using fields. Then we need to generate
the getters and setters. Let's go to source, generate getters and setters. Check all the fields. Click on Generate. The getters and
setters are generated. Next we need to String. Tostring method will generate. So Entity classes
ready receive this. Next we need the
video doubtless, similar to user down. Right-click new class
named meatus, video. Dao. Okay. You can remove the
default constructor and click on Finish. These are video DAO. Now what we'll do is
we'll simply copy this code from user down
because it will help us. So copy this and paste it. Okay, Now we need to
make some modification. So connection con, we need
for the connection class. And instead of entities here
will be needing the video. So use video. Now will be used actually here will not only be sending
back a single video, but a lot of videos. I mean, whatever will be there
inside the videos table, all the videos will send. So it's better that we
create our result set. Okay? So that is L sake,
we'll be sending back. And this one we do not need. So we'll set it as
get, all videos. Get. Okay, let me remove this user. We do not need it. Okay. The next thing is, we
didn't also do not need the user declaration. Yeah, we need the JDBC
connect and JDBC. This is a GC which
is the object of the DVC connect and corn equal to d c dot
create connection. This will create a connection. Next we'll need the query. So select star from videos. And we will not be using the dynamic query here because
we need all the videos. So just select star from videos. Now, we'll also need the prepared statements
and also remove the prepared statement and
replace it with statement. Statement SD equal
to con dot create. Inside this will have all ready, which is this one. Okay. Let's import the statement.
What it is saying. Remove argument to
match create statement. Okay, we do not need
the fatty here. Remove this. Next us to import statement. Statement should be imported
from Java dot is given. Okay? Next we have the result
set sd dot execute query. And within this we need to give, okay, Now I will remove this one totally.
We do not need it. And what I'll do is I will
create a result set above. Result set. Set equal to nine. Okay? And we'll use this set here. And we need to reserve return. The result says
return the set here. And here we'll have
the, the result set. So a Dover of the
response we get back from this query execution. We will return the
whole result set to the place where this video
down will be called. I'll also remove this
prepared statement because we do not need it here. Because this is a static very, very fetching the regions
of all the videos. In the next video, we'll
see how we can face the videos from the video table
from our welcome dot GSP. Thank you for
watching this video. See you in the next lesson.
34. Project - Ready to deploy: Hey guys, welcome
back to the course. In this video, we'll
see how we can face the videos from this video
down to our welcome dot tasty. So for that, what you need to do is come to your welcome dot JSP. And then after the nephron, we need to, we need to actually create an object
for the video doubtless. Video, Dao. Dao equal to mu. The video. Now again, we need to import this
particular video now. So for that, we go above. After this, you can
simply write a coma dot, dot dot v d. Okay? Now if you scroll down silicone, now many to fetch
all the videos. So the result set inside this, we need to have
all those videos. Result set videos equal
to then video DAO dot. Get. What was the
name of the class? Sorry, the method
that is go and check. So this is good. All videos. Okay, so we need this metric. Let's copy this. Go back to welcome not
JSP and pasted this vent. Give back all our
videos to us now, we need to also import
the java dot sequence. So let's do that. Let's open a directive
tag and let's import java dot. Excuse me. See if this what is it showing? It cannot be resolved. Why is it so we have imported. Okay, we need to use form. Let us press control space. I think we can get
some suggestions. Java that secret lot
star, Let's see. Yes. So we need to import Java
dot is two L dot star. It will import all the sub
classes and sub packages. And this test is on the issue. So doesn't set we
have we can run a while loop, videos dot next. And we can simply print them. So we can write. So what I will do
is I will close the script plate here and
open this triplet here. Within this, I will use BTEX. So later we'll modify this
and use some Bootstrap table. For now. Just to see the
output we can use this way. Let's use a p tag and use
our expression. Here. We need to print it. Print set, dot. Not safe video, videos, dot, get, string, underscore. This should be within quotes. So V and the score. Okay? Okay. And we can close the
p tech. Similarly. Copy this. I'm good, I eat via underscore. And we'll use it. Let's save this and run it and see if
we can get some output. So right-click, but I miss. So next, finish. So let's login user one. And now we need to
give the password. Okay, there's some edit, Let's check it out. So these are Jasper,
It's exception. Okay. So let us look into the issue. So in this video, let's see what is the
era they're showing. There is an extra brace. Okay? So let's remove the
extra brace and save it. Okay? So still it is showing
some editor written. Simply close the extra space. We DO start GetString. Just corrected me.
Let's restart Eclipse. I think sometimes distracting can also help, so let's do that. So if you see here also, I think unnumbered to
compile class is theta. And in the 5253 we can see there is an extra
brace which is closed. He does restarted. Let's wait for the
clips to start. Yes, there it is gone. So sometimes you know, things that reflect
at that very instant. So in that case, if you
face any such issue, you can now go ahead
and refresh or restart. Your Eclipse ID. Letter will be gone. So let's run now. Right-click. Run on silver. Next. Finish. Really
get restarted. Okay, let's login now. Give the username
and password submit. And you're sticking a while. Okay? So see we have learned
HTML and W3 schools link. Okay, now we need to modify
the code in our welcome or JASP so that we can see
these details in a table. So let's go to google. Now let us search for Bootstrap. Okay? So we can
choose the tables. So I think this view
is looking good. So I will copy this
table. Let's go back. So it'll go back
to our workspace. Now. We want to
change anything here. First of all, let us paste the code for the table and we need to modify
some things there. And then we'll see
how we can write the values of the videos like the title and the URL
in it after that. So let us do it
after the script, or maybe after this one. Paste it. Now I think there are two
tables which are copied. One table I will remove. Okay? We need only one table. So this is the table we have. Now. Let us give
the column names. We need video title. So title. So we only
need two columns. So I will remove
the third column. You can also remove the id, or if you wish, you can keep
it as well. Let us keep it. So title and URL. And in the row, we need
to now paste the values. So row number here
will remove this one. And instead of this one, we will write all these values. So what we'll do is we will copy this and paste here. And here also. He didn't really give
v underscore ID. And here also paste here will give v underscore. Okay? Now the thing is that we do
not need to repeat the code. We do not need to
depict the code. So we will simply remove the
two TR's which are extra. Now, we will dig this
up to table body, will cut this and paste it here. And within the body, we will remove this. We will have TO that
the body and the table. We will write it. I think we can write it. After this curly brace. You need to close
the script lit here, because the while
loop is closing here. So you have to close
this triplet and you need to open another triplet. Okay, let's save this and
let's run it. Right-click. Run on a server. Next, finish. Again, we need to
give the credentials, give the username and password. And now we have our table. Here. We have done, we do ID and this
video title and URL. Okay? The next thing what we can
do is we can make it Lake, keep it inside an anchor tag. So let's go back. Okay, So now here in this TD, right, and anchor text, so h of x equal to
two, give me water. And we can end the anchor tag. And also we can give the target equal to
underscore blank. This will make sure
it opens in a new, new, what I can say or tap. This target
underscore blank will ensure that this URL
opens in a new tab. Now we also need to give them. So for h, we can copy
and paste this one. This is fine. Now let us
see if this actually works. On solar. Click on Finish. Again, give the credentials,
username, and password. Yeah. So we have learned
HTML and we have a URL. So here, if I click on this URL, it opens it in a new tab and see our new
website is opened. In this way, you can give multiple entries to your stable. And you can see by launching
the videos, click on logo. So our project is done. We have learned
how we can create a user login module and how
we can create a logo module. And also how we can
retrieve the data and show it on the homepage
once the user logs in. So you can try this project. I mean now you can,
instead of videos, you can Use leak or
notes or something. Or you can use images. So any kind of content
which you want to use, you can use it in
the homepage and you can create a corresponding
database for that. So try this user login, logout, and the homepage content section by yourself in your Eclipse ID. And practice this
so that you can understand how this
DSP is working. So this project will help you to get a good grasp
of the concepts. Thank you for
watching this video. See you in the next lesson.
35. Class Project and Tips & Tricks: It's time for the class project. Now, for the class project, you need to create a project website in your Eclipse where
we'll have the logo, logo, homepage, and
the content modules. And then for the
tips and tricks, use Eclipse IDE for
coding as you can get a lot of built-in
facilities state. Now, the next is give
proper indentation because indentation makes
the code look beautiful. And you can also find out
areas if you face any. The next step would be do
not panic if you get stuck, you can debug the code, makes sure that all the classes which are required are imported. And you can also import the required jars
in your Eclipse ID. And the deliverable would
be the screenshot of the project website that
couldn't be creating using GSP. Thank you and good luck.
36. Thank You!: Hi guys, congratulations
for making it till the end. I hope this course has helped you to learn the skills
in a better way. Please do not forget to leave
reviews for this course. For more updates, you
can join my answer them community where I share
a lot of content, learning materials and lot more. Thank you for your time and I wish you all the
very best in life. Keep learning.