JSP and SERVLETS Tutorial : First Java Web Application In 25 STEPS

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi there welcome to this course on your first java web application in 25 steps I am Rangga Cottenham I have more than a decade's experience in developing java web applications in this course I will take you through series of 25 steps which would help you in creating a simple web application with login logout functionality and also to do management functionality during this course we would touch upon the basic concepts of Java web application development request response get post servlets JSP e l filters we use html5 and bootstrap to style our web application and we use maven to run our web application on Tomcat to be able to follow this course you need to have some experience with Java I will help you install a clip and also to get up and running with maven and Tomcat all the code for this particular course is available in the github repository in 28 minutes Java Web Application step-by-step this repository contains the code at the end of each step of our tutorial starting from step one to step twenty-five what are we waiting for let's create our first web application together in 25 step in this course we would be using a clip as the ID if you don't have Eclipse already installed then you can use complete installation guide for Java and Eclipse including melon which is present in our github repository if you go into Java Web Application step-by-step this is where you end up so this is the github repository and if you go further down in here there is a PDF link so if you open this guide up it would help you to install Java Eclipse and also Mallen in this course we would use the embedded maven inside Eclipse so you don't need to separately install mavin all that you need is to install java and eclipse once you have it ready we are ready to go before we discuss any theory about web application let's get our hands dirty and also start with creating our first step by the end of this step you would have a simple web application running in Tomcat let's get started the simplest way to create a web application in Eclipse is by saying right click new other and type in Marilyn Beauty maven project mavin is a Java build tool and it helps us to manage all the dependencies for our web application it's quite a simple tool if you understand it correctly and if you create a web application as a mavin project it brings in a huge deal of benefits which will make use of during this course so let's go ahead and click Next maven project and I'll create a very simple project I do not want to use archetypes I mean archetypes armaments way of creating sample projects in this particular course I don't want to use archetypes because we want to configure each step ourselves we want to do this course step by step so I would create the web application step by step so I choose create a simple project I would say use default workspace location once I say use default workspace location Eclipse would use the same workspace to store all the code that's not a problem so go ahead and use use default workspace location and click any mavin project that we create needs to have a name a name consists of two parts one is group ID the other one is artifact ID group ID is like package name so I give in something like com dot in 28 minutes that's what we are giving as group ID and the artifact ID it's a first web application so I would say first web application the version don't really worry about it leave it at default packaging I would change it to work we want to create a web application a web application is var var stands for web archive jar stands for Java archive so we want to create a wire of web archive we want to create a web application so I choose a wire so I now go ahead and click finish Eclipse will take a while before it creates the first project once it's up and running we can get started once you open up the project which was created the first web application you would see all the folders that you see on the screen right now the importing folders are source main Java source main Java is where we would put in all the Java resources so whatever is shown as Java resources in here the most important folder is source main Java source main resources consists of all the resources that we need as part of the source file so if you need a properties file or if you need a XML file prop you put it in source main resources we would not create any test code during this particular course so you don't need to really worry about source tests Java if you are interested in unit testing and you create unit tests these are the folders where you would create those unit tests other than this you would see a deployment descriptor right now if you double click on any of this you would see a message saying the web dot XML does not exist don't worry about it we would create a web web products ml very soon and also you would see a pond dot XML so if I open the pond dot XML you would see just a little bit of configuration I mean the group ID which we created I mean which we gave as input and the artifact ID and the version all these were the inputs which we provided in the IDE early and these were used to create a bond XML app on dot XML is the most important component which is used by mavin mavin is a Java dependency management to to run a web application you need a lot of chars for example if I'm running a web application with spring hibernate then I need spring Georgia hibernate Roger instead of myself going individually and downloading each of the chars I can ask mavin to download the jars for me this work which mavin does is called dependency management once we add a dependency in pond or XML mavin would automatically go and get it from a repository and make it available for this project we will use this feature of mavin extensively during this particular application it memorized quite a very simple tool to understand and it makes the life of a web developer very very easy as a student I really hate courses where I am asked to copy a lot of stuff I really like to do things step by step I kind of give an exception to that rule in this first step hello in my experience I saw many students make error in the first step and unable to recover from it so in this first step alone we would copy three files from the repository you would spend a lot of time analyzing them but we would copy them for this step alone the first file we would copy is palm dot XML so I would start from here and select the entire content of the file copy and open up the palm erotic smell that we have and paste it in there are two important things that we need to discuss about this bound or XML which we will discuss very soon let's pound our XML the first file that we copied the second file that we want to create is the login servlet dot Java what I'll do is I'll copy this entire code control C so rightly copy and you can paste it directly in source main Java so you can go to write source main de Java and say right click paste there will be a few compilation errors which would be coming up don't worry about them right now the last file which we will copy is the web dot XML it's in a folder called web-inf so what I will do is I will create a folder called web banner so in web app I'll create a new folder called web-inf and in here I'll also create a new XML file I want to call this web small web dot XML and I copy the content from here in there so I will copy whatever is in here into this effectively there are three files that we have created the first one is the ponder'd XML in the pond or XML we copied the content in we created a login servlet and we copied in the web dot XML these are the three files that we copied in I am sure this would be one of the last times we copy the entire file during this course after you copied in the files you can do a right click mavin update project we have done a few mavin changes and we need to update those changes we do right click maven update project you'd see that all the errors disappear and now we have a complete web application configured before we look into the actual content of the Pounder XML login servlet dot Java and web or XML let's try and run this application there is a lot of magic that we created in these three small files that we added in let's see what that magic is right now so I am doing right click run as maven build and you can type in Tomcat 7 so this a plugin called Tomcat 7 that we configured we look into very soon and say run Tomcat 7 : run so it's Tomcat 7 : wrong in click run you see a lot of things happening in the console you would see that there are a lot of files getting created and also the Tomcat server would be started now the Tomcat server is running and it also is printing the URL in here so if you look at it in control they would be somewhere it says HTTP colon localhost colon ta D or whatever port you are using let's launch up a browser and type in localhost colon 8080 and press Enter you would see some response coming back it says my first servlet and the heading is Yahoo you might ask me we have a servlet running printing my first servlet but how is it really working what is in this servlet who downloaded Tomcat you have not downloaded Tomcat at all until now right it's running in Tomcat how is it possible and what is in the web products ml lot of questions unanswered we will try and answer these questions in the theory part of this particular step there are a lot of unanswered questions but the thing you can be proud of is the fact that you have a web application running in ten minutes flat now let's try and answer your questions first let's look at the pawn dot XML there are three things that you need to understand in the poem dot XML what we did is we ran the web application in Tomcat how did we download Tomcat actually Marin did it for us we configured a plugin in here which is called a tomcat male and Tomcat 7 plugin which takes care of downloading the Tomcat and running the web application in there so that's your first question so to be able to run the web application in Tomcat we use something called Tomcat 7 Myron plug-in there is another plugin which we configured in here the second plug-in which we configured in here is something called a mavin compiler plug-in my own takes care of compiling the Java classes that we created and also building the jars and the Wars the default Java version which the compiler uses is 1.5 but I am creating a je6 application which needs minimum of Java 7 so I would want to configure this particular web application to use 1.7 to use the source Java source version as 1.7 and the target version also as 1.7 the way we did that is by using a plug-in a maven compiler plug-in and in the configuration of the plug-in we set source and target the most important thing about these two plugins is the fact that once we have configured them we are not going to change them throughout the course so if you are not understanding them completely it's okay or you might even do a google search on mavin compiler plug-in and Tomcat 7 ma and plugin to understand a little more about them the third thing in the poem that XML that we have added in is the dependency we are running a Java EE 6 web application how do we add the Java EE Web API jar to the code in this servlet if you look at the servlet this extends a hash TTP servlet the HTTP servlet is defined in Java X servlet HTTP we need to provide this jar to the java application so to this web application we need to add the jar in so what we did is in the palm dot xml we added that jar as a dependency if you go and expand the libraries section you would see in the maven dependencies a Java EE Web API dot jar and if you go in you would see the Java X dot servlet dot HD p dot HTTP servlet defined in there since we want to create a servlet and we want to use Java EE we have added in the dependency on Java EE Web API you would see that if I'd remove this dependency let's say I am removing this dependency and I am doing a safe you would see that in the my own dependencies we don't have anything right now so we don't have anything in the moment dependencies the second thing which you would have is that there is a compilation error on the login servlet because now there is no HTTP servlet class available to create a servlet we need to extend the HTTP servlet but the HTTP servlet class is not available in this particular web application the way we are adding in the Java EE API war is by adding a dependency in here once we add the dependency in you would see that all the errors would disappear and we have a compiling login servlet so that's the pond dot XML the important things in the pond dot XML is we added in two plugins the first plug-in to be able to run the web application in tomcat the second plug-in to be able to compile the code using Java 1.7 source and target as Java 1.7 the third thing we added in is a dependency on the Java EE Web API we want to make use of Java EE version six and we are making that jar available as a dependency to this particular project those are the three things which are important from the perspective of a pom dot XML the next file we would be looking at is the web dot XML in the web dot XML all that we did is we created a welcome file called login dot two whenever somebody types in localhost 8080 we want them to go to login dot two that what the Welcome file does welcome file is a simple redirection when you type in localhost colon 8080 it redirects to localhost colon 8080 slash leg in dot do that's all with it that all the content there is in the web dot XML the other important thing which is there in the web dot XML is the fact that we are using the specification version 3.0 so 3.0 is the latest version and we are using 3.0 so we are using we are creating a web app version 3.0 and we gave a display name to this particular project as to-do-list because we want to build to do management application that the web dot xml actually the content in web dot xml is really simple compared to the content in the Palm D'Or XML the last file which we have created in here is the login servlet the logging servlet is a servlet what does that mean login servlet extends HTTP servlet what is HTTP servlet that is what we would discuss in the next chap in this course we are creating a je6 web application je stands for Java platform Enterprise Edition and we are going to use this technology to build our web application the best place to get all the documentation about the jev platform is the oracle website so if you go to the oracle website the URL is in here I mean the simplest way to get to this would be just say je6 documentation and search in google this would be the first result which would usually come in Java EE is nothing but a set of specifications that define how various things are developed in java enterprise applications the specific thing that we are focusing on in this particular course is the Java servlet technology so we are going to use java servlets to create our web application there are a lot of other things in the java ee specification like JSF JPA java persistence api jax-rs how do you develop less web services with java and things like JMS how do you interact using JMS Java messaging service with other applications our focus would be on understanding how to develop web applications using the Java servlet technology now that we have a little bit of background on je e request/response we are ready to answer the question what is a servlet a servlet is nothing but a very simple Java class which can take requests in and can respond back with the response so a servlet takes input as a request and give the response as the output that's basically what a servlet is in this course we are only interested in web requests the HTTP requests and HTTP responds so we are really interested in HTTP servlet basically the servlets which can take a hatchet EP requests as input and a HTTP response as an output now let's look at our first example servlet before we discuss about the login servlet let's run the web application again I'll do a right click run as mvn bill Tomcat 7 if you already have it running that's ok but I have stopped it so now I would go ahead and run it again it takes a few seconds for this server to start up and now I can visit the page localhost colon 8080 one tip which might help you if you get a poll already in use exception for example I'll run click my server is already running so I will go ahead and run it again so I'll do right click run as a VN bill I will choose talk at 7th round so this would try and launch up the server again I already have the server launched up but what I am doing is I am trying to launch it up again you get an exception saying Java net bind exception address already in use this would not launch up the server because the port 8080 is already used by a server which is already launched up so what you can actually do in that kind of situation is actually terminate the server fir and you can double click the this arrow which is in there and then you would go to the server instance which is already running if you would want actually you can kill this server and launch it up again or if it already has the latest code then you can use the already running version let's now go to localhost 8080 what we see on the screen is my first servlet and I also see a Yahoo in here what we do is we want to understand what happens behind the screen for this so what we would need to do is use right-click and do inspect element I'm using Firefox so if you are using Firefox to right-click and do inspect element once we do right click inspect element we get into the developer tools section of far form there are a lot of features in here the one which we are really interested in is network so I would go to network and I would reload the page so what I'll do is I'll reload the page again what you three when I go to the all tab is a request for it I am doing an inspect element I would go to the network tab and reload the page again and then you would see something happening behind the screen so what you are seeing in here is what is called a get request this is how the web applications work irrespective of the technology they use behind the screen what they do is they use something called a request so when we typed in localhost colon 8080 what the browser does is it creates a request and sends a request to this particular server it sends a request to localhost 8080 what kind of request it's a get request we'll understand the difference between gate and a post a little later but in this particular situation what we are sending is a get request to the request URL localhost colon 8080 along with the request a few request headers are also sent if you looked at it here it shows the browser I am using mozilla 5.0 and there are a few other parameters which are sent along with the request headers that's not really important for you but you need to understand that there is something called request headers when we typed in localhost 8080 we are actually creating a get request to localhost 8080 and along with the get request there are a few request headers which are sending that the request now what was the response that came back I would go and click the response which is the fourth tab on my screen right now and the response you see is a HTML so you'd see that there is some HTML coming back from the server so when the server got this request when server got the HTTP request localhost 8080 what it did is it responded back with this particular response what is the response contain the response contains very simple HTML HTML it contains a little bit a title and it contains a little bit of body what which we see on the screen right now so my first servlet is cut in side the body and Yahoo is the title and that's what you see in so when this server got the request when the webserver got the request localhost:8080 it responded back with a response so this is h DP request and this is h TP response along with the response also there are a few headers which are sent back so if you see what is the date I mean what is the time on this server and what is the type of server what is the length of the response that returned back those are the response headers which are returned back from this server so if we look at it at a high level it's very simple when I type in localhost 8080 the browser creates a get request to localhost 8080 along with a few request headers the request goes to the server and the server is responding back with a HTTP response which contains the HTML content as well as a few headers on the response this is how all the web applications work you can try this on other websites too you can probably go to google.com and see what's happening in the background you can go to other websites and see what's going to the background and you would see a lot of requests and responses happening in the background so to summarize what we have seen until now when I type in a URL in the browser bar the browser sends something called a HTTP request to the web server in this specific case we were looking at it was a get request and the web server once it gets the request it rents responds back with a HTTP response what we are building as part of this web application is the code in the web server browser since HTTP request to web server so what should the web server do what should the code in the web server do it should take decoding the web server should take the HTTP request it should take the HTTP request as input so the HTTP request is input to the code in the web server and what is the output the output is what does the web server needs to give that it needs to give back an HTTP response so the output is HTTP response so the input to the web server code is a hash TDP request and the output from the code in the web server is a hex DP response let's look at the sequence of steps again I type in a URL in the browser bar the browser creates a HTTP request sends it to the web server the code in the web server it looks at the HTTP request and based on the content of the HTTP request it rents responds back with a HTTP response the HTTP response is sent back to the browser and the browser would show the page that basically the entire flow for any web let's now consider the important part in creating a sample servlet the servlet that we are creating in here is the login servlet the login servlet if you look at it it extends the httpservlet the HTTP servlet is defined in the package Java X servlet HTTP HTTP servlet this is coming from the je e specification so any servlet should extend HTTP servlet that's number one so we extend the HTTP servlet the second thing is what is the URL to this servlet so when I type in localhost 8080 we came in here how did we come in here we use something called a URL the URL which is assigned to this particular servlet is login dot do to assign a URL to this servlet we used an annotation called @ web server late at web server late is a new annotation in je6 it's in the package our ex servlet annotation web server late and it defines it helps us define the URL patterns for this particular URL and annotation is something which adds more information onto a class this particular class we defined it as a HTTP servlet but we also want to add more information onto it we want to add the URL for it for that sake we use a webserver let annotation the webserver let annotation adds more information to the login servlet now we are saying web server it with a URL pattern login dot do so we are saying how do we call the login servlet you have to type in slash login dot do let's do this quickly ensure typing in localhost colon 8080 I would say localhost colon 8080 slash in dot do so we typed in login dot do instead of localhost colon 8080 so we tied in localhost localhost colon 8080 slash knockin dot do and now I see the output soon logging to do is basically the URL which is used to invoke this particular servlet earlier we saw that we are sending a get request so the request which we are sending in is of a type get the method if you see is get request to handle that we need to create a do get method if you look at the HTTP servlet it defines a couple of methods in here the one which we are interested in is this particular method do get the do get method is used to handle get request so we create a do get method so we created a do get method which has two inputs or two parameters the first one is the httpservletrequest and the output from it is the httpservletresponse so request is the input response is the output so that's what we learnt earlier for any servlet what is the input request what is the output response so we read from the request and put information back in the response that's what we do so we created a method do get to handle the request to login dot do what kind of request we are going to handle the get request that why it's called do get so we are going to handle the get request to login dot do and we are going to send a response back what we would have in the response is what we are writing in here so we are getting a writer object from the response so we are doing a response dot getwriter and getting a printwriter object out and from here it's very simple to simple thing like a system dot out dot println so I am doing an out dot println whatever content needs to be sent in the response so I am saying out dot println HTML head title so if you look at the response back for this particular thing if I highlight this and see the response you'd see that the response here exactly matches what we are typing in whatever changes I would make in here you would see in the response as well so if I go ahead and change let's say Yahoo I would change it I will remove the semicolons at the end and just say title Yahoo give it some time for the context to reload and we are ready now I go ahead and type this again you see that now the title is changed to Yahoo whatever it is in this particular servlet is being returned back as their response these are the four important things first one any servlet should extend HTTP servlet for any servlet I would want to give it a URL the way we do that is by using an annotation at web server let and passing a parameter URL patterns in this servlet we need to define what kind of methods I would want to handle I would want to handle request method get or request method post so in this example we are looking at request method get' and we defined or do get httpservletrequest and httpservletresponse method in this method request is the input and response is the output and how did we create the response we took the get writer and we wrote some output into the print writer what I will recommend you to do is try and play around with this particular servlet try and make changes to it try and change the URL try and change the content which is printed in try and play around with it for about 10 minutes to get more understanding about this particular servlet we will discuss this servlet more in the next step and also try and create this from scratch this has been a very long but very interesting step one we understood this request/response flow we understood how the browser creates the HTTP requests and how the web server responds back with a HTTP response we understood how to create our first login servlet we looked at important things like bounded XML and web dot XML and probably you are introduced to a lot of new terminology as well this is probably the longest and probably the most important of the 25 steps that we would discuss as part of this course so I will really recommend you to repeat this step if you have any questions so are we ready to move on to the next step in this step we will do two things one is we'll create the login servlet from scratch and the second one is we would start using a JSP instead of writing content directly from the servlet let's get started with the first I'll delete the login servlet completely and stop the server as well we now want to create a login servlet so what I'll do is right click on the source main Java and say new cloud the package I will use is you can use anything actually let's use comma dot in 28-minute and the name we already know it's login servlet click finish the first step in creating a servlet is you need to extend what do you need to extend we discussed that in the previous class you need to extend HTTP servlet and if you type in history servlet and press ctrl spacebar we need to do the import of HTTP servlet and Eclipse provides an easy way of doing that that's control spacebar so press control + spacebar together and it would show what are the options and I would choose the first one so I would press Enter you would see that now this particular import is added in so what did we import we imported the HTTP servlet so that's very good that's a very good start now I would want to go ahead and add the URL to this how do we add the URL by using the annotation web server later I type in back at web server let annotation stops wait at web server let is the name of the annotation type it in and press ctrl spacebar and you already see that it's imported so the web server late is now imported so it's this is import which is used and now to this I would want to add in a parameter for the URL so how do I add in a URL I open I put in a Open bracket close bracket and press control space again and it shows the options the option I want to use is URL pattern so I would use URL patterns and give it a value what's the URL pattern that we want to give it to this login dot do most important thing is the URL pattern should start with a slash slash login dot do that's the URL pattern that we are assigning to this particular servlet let's go ahead and now add in the next important thing which is we want to handle the get method so we want to handle the get request so I go to the HTTP servlet class and copy this so this is the definition which we are going to use so I'll copy that in this is the method which we are going to override on the HTTP servlet so the do get method we are going to implement so I don't want to use the package names directly in here so I will remove the package name you can press control space at the end of it and import the Java and similarly in here httpservletrequest also I would want to import one way of doing this would have been to just copy this and import that per ticket class now I don't need to do this here so that's simple so now we have a httpservletrequest httpservletresponse it's called add zero I hit that and call this request and let's call this response let's go ahead and also import these two classes as well Java excellent I don't need it so I need it but I don't need the package definition directly in the code so I will do control space again at the end of servlet exception so I'll go to the end of servlet exception do control space so we have imported that in now IO expect exception also let's remove the package definition go to the end press control space I would want to use a I expect exception from the Java I you that's it we have now a simple do get method defined so now we want to write to the response to be able to write to the response we need get a writer so get writer so that's the third step so we are now getting the writer sorry that's the fourth step the third step was to define the do gate method we have done that successfully and now we are getting the response dot getwriter print writer writer is equal to response dot getwriter you can import in the print writer as well so it's in java io print writer writer dot print Ln some dummy stuff I don't really care what it is I just want to send this back and see whether this is getting printed to the browser is not really a hedge tml response but I don't really care the first thing I care is whether it's working so I'll go ahead and do a run as ambient build and choose Tomcat 7 : run which we used earlier I would wait for the server to start up and refresh the browser the URL which we gave it is login dot do now I plus a refresh again and you see that dummy stuff is printed out to the console so if I look at the get request the response which came back is what we tied in dummy stuff so if I go ahead and change the response now from that my stuff and add in one more line dummy stuff to hold on to a little time until you see read old in context is completed once the reload is completed the servlet is reloaded and now I can refresh and you see dummy stuff dummy stuff too and if I look at the response its dumbest of the mist of two actually this is not really a good way of doing it the browser understands HTML and we need to send the data which we want to show on the browser in HTML format what I have done now is I copied a little bit of content in here so it's HTML head title Yahoo head body slash body HTML this is a well formatted HTML the other thing which I have done is also renamed the variable instead of calling it writer I called it out so now this particular piece of code would print whatever you see on the screen so whatever you see in the double quotes would be printed out to the browser would be sent as a response to the browser it's not really printing out to the browser what happens is a request is sent and in response you would get whatever we have in this thing so we have exactly this in here as well so that's how your servlet works a sublet gets a high should be request we send our HTTP response back we looked at the four steps in creating this servlet in here now let's go ahead and change the is to a JSP I know the first question is why should we go for a JSP why can't we keep writing code like this a servlet is a Java class Java is a language where it's easy to do business logic what we are doing in this particular servlet is trying to send some HTML content out to the browser so we wanted to send this response out to the browser that's not what Java is good at Java is really good at doing business logic and not really good at sending static content out because I have to repeat out dot println so many times in here Java EE came up with this concept of jsps Java server pages these Java server pages are designed to make writing dynamic content to the web browser very easy one important thing you need to know is even J's piece finally compile to a servlet so even though I write a JSP at the end the JSP would be converted to a servlet so there is not really any performance benefit in going for a JSP because a JSP also converts to a servlet by the end anyway the reason why we use J's piece is that it's easier to write dynamic HTML content in a JSP rather than in a servlet let's go ahead and create our first JSP typically in a web application we write all our Java code in source main Java and we have all our J's piece in a folder where by now I would want to create a folder for the views JSP is a view so I would create a new folder in web-inf I will call this views I flick finish and I'll create right click new JSP files we want to use this for login so I would call this login dot JSP you have the first JSP file created with a lot of things in here by default Eclipse is generating a doctype HTML 4.0 is hash tml 4 I'll remove all the content so that it becomes HTML 5 so the default is HTML 5 so when I say doctype HTML the default is HTML 5 so now I have a html5 JSP except that the title needs some customization so what we want to do in the title is what we did in login servlet so let's go ahead and put a title as as Yahoo from JSP just for us to be sure that it's coming from the JSP so Yahoo from JSP JSP so now we have a simple JSP created this follows typical HTML structure we have very little content in the body just says my first JSP the JSP is ready in the servlet we need to redirect to the JSP when user hits will again dot do URL we want to go we want him to go from the servlet to the JSP we want to redirect him from the servlet 2g JSP how do we do that the way we redirect a request to a JSP is very simple you need to do request get request dispatcher so this is a get request dispatcher is a method on the request and to this I need to pass in where the JSP is so where is the JSP so I need to pass in where my JSP is and forward the request to it so I'll pass in forward request comma response redirect into a JSP is very very simple the first thing is you'd get the request dispatcher so I get the request dispatcher and point it to where my JSP is this particular thing is not really correct right now so wherever my JSP is I would need to put it in here and I would for the request response to it so that's it that's how you forward it to a JSP but now I would need to give it the path to the JSP the way we get give the path to a JSP in a servlet in a java web application is starting from Y by an F so I would need to start from whereby enough so the path if we look at it is what is the path where is the login gorgeously pleasant in starting from beben F slash web-inf slash views slash login dot JSP that's basically where our JSP is in web enough views login dot JSP and i typed it in here bye bye enough views login dot JSP love the servlet would redirect to the JSP let's see if it's working let's go to the browser and I would type in localhost colon 8080 slash login dot do there you go you have the content coming out from the JSP my first JSP Yahoo from JSP so you have your first HTML content output from your JSP so in this step we had actually created the login servlet by hand and then we made it redirect to a JSP we use jsps because in a JSP it's easy to write HTML content earlier in the servlet we had to do a lot of out dot println to generate this content out but in a JSP you just keep writing HTML out and it would be output it would be sent back in the response to the browser as in a lot of things before steps in developing a web application are the most difficult ones you have now completed two steps and these two steps in my perspective are the most difficult steps to take and from here on it will be an easy right let's get going until the next step bye-bye the best way to learn something is by developing a playful attitude towards it now that you completed the first two steps I would really recommend you take a break and play around with this particular code that we already have what would happen if I change the URL and pattern to login what would the thing continue working what would happen if I change the JSP to an organ existing JSP if I change it to login one dot JSP if you are new to eclipse then you can try and play around with the imports as well how is Eclipse getting the import directly when I go somewhere and type in control space so I went into servlet exception press control space and the import or medically comes in how does it happen try and play around with these things there are a lot of new things that we are talking about in this particular steps in the last couple of steps especially and the best way to get good knowledge about them is play around with it play around with the URLs play around with the J's please play around with the login servlet and see what more knowledge you can gain through that we have configured the Tomcat plug-in to automatically restart or reload the context if there is a change that's why you would see that when I change something in here I'm changing changing login due to login one dot do and pressing save then you would see that they come in the console that the context will be reloaded you know so now you see that the context is reloaded same thing if I change anything in the servlet login one dot JSP for example the context would be reloaded this would save you a lot of time because of this you don't really need to restart the server each time so you don't need to stop and start the server whenever you make changes in the servlets the only time you need to change restart the server is when you create new servlet or make major changes in there for all the minor changes those would be automatically loaded into the Tomcat server for example now let's get it back to login dot do and I am leaving the JSP s login one dot JSP as we know the login one P is not pleasant we only have a login dot JSP we don't have a login dot one dot JSP so what would happen aha we get a HTTP status 404 it says web-inf login 1 dot JSP not found the requested resource is not a very level that's the error so it means that the change we have done is deployed that's one thing the other important thing is the HTTP status along with the request when I send a request to a server I get a response back one of the major things which is present in a response is something called the response status in here when I have a page not found I got a 404 this means it's a page not front let's change it back to login to JSP wait for the context to reload yeah it's done and do a refresh you would see that the response status is 200 so that's another important thing the response status the response status for a successful response is 200 usually it's 200 and when there is a failure the response status can be a different number when it's a page not found it's usually 404 that's why 404 is a famous status lot of techies used for altered it to signify that something is not really formed in this small chapter we just wanted to take a pause and look around and see what other things that you can learn about the application that we have already developed I will see you in the next step let's now move on to our next step we have a login dot do login servlet created which is redirecting to a login JSP when we type in the login dot do URL my first JSP is coming up and you can see the response and also you can see the headers and the parents in your browser that's what we have done until now one thing you have already noticed is the fact that when I type in localhost 8080 also the same response is coming back so even when I type in localhost 8080 and localhost 8080 slash login dot do we are getting the same response back how is it happening the answer to that is in your web dot XML in the web dot XML we configured a welcome file as login dot do what our applications are what our webserver would do is whenever there is a request with no nothing behind it so when there is a request with nothing behind it what it would do is it would automatically forward to login dot do so this forward would happen automatically and that's why you would see even when I type in a URL without login dot do my first JSP is automatically print in this step what we would discuss is something called a get parameter how do we pass parameters to the request one of the ways I can pass a parameter to the request is by using a get parameter how do we do that the way you pass in a parameter is by putting a question mark and giving a name of the parameter first the name of this parameter I would call it name and I would pass in the name so I'll say 20 in 28 minutes is the name so when I do this let's see what happens name is equal to in 28 minutes effectively the URL you would be typing in it's localhost colon 8080 don't forget the HTTP in here because sometimes Firefox is taking you to Google instead of bringing our web application up so it's HTTP colon slash slash so that's where it starts localhost 8080 is where our web application is deployed I am creating a parameter by name name and the value and passing in is in 28 minutes and the question mark is to separate the URL from the parameter so what I am doing is I'm separating the web server name and the servlet name from the parameters using question mark so after question mark you can pass any number of parameters so now when I press ENTER here you would see that the my first JSP comes in there is no change because we have not used this parameter in our servlet code so there is no change in the JSP and the output from the JSP but if you look at the request you see a few changes I am going to the request I mean the way you can get this get here by is doing right click inspect element and going to the network tab so go to the network tab and you should refresh the page again you should see this get request and if I go to the headers in this particular request you would see a few important thing the request URL is now the complete URL including the parameters that we passed and this is a get request that we already know this is a get request we look at post request a little later the status is 200 that means everything is fine along with the request there is something called parameters what are the parameters that were passed the parameters which were passed were passed as part of the query string and what were the parameters name in 28 minutes so name with a value in 28 minutes is a parameter that is passed along with this particular request these are what are called request parameters so the way I pass a get request parameter is by appending it after the question mark question mark name is equal to in 28 minutes so name is a parameter now we have sent the parameter from the browser but how do we use it from the servlet but what we are going to look at right now so let's go back to our login servlet in this servlet we are not really using the parameter let's use it now the way you can get a parameter from request is by using request dot get parameter and I would need to put the parameter name in here so outside request dot getparameter name let us do a sis out not the best way actually ideally I should be using logger but let's take a shortcut this out and I would put in the request dot parameter name let's wait for this servlet to reload its reloaded now and I would refresh this page so now there's no change in what you see in here but if we go to the console you'd see that the in 28 minutes is printed on the console that's because we did assist out dot println request dot getparameter name in 28 minutes is printed in now let's pass in a different min just to make sure that we are actually picking up the meme I am passing in a different name let's say I'm passing in Radhika my daughter's name aha what would happen AHA you'd see rithika in here as well we are passing request parameter from the browser and we are printing it on the output so we see the request parameter on the servlet so now I would want to pass this request parameter from this servlet to the JSP so whatever value I am getting in the servlet I would want to pass it to the JSP how do I do that that the next important thing that you would learn the first thing which we learnt is how we would pass a request parameter and see that in the servlet that we have seen we need to use request dot getparameter name so that gives me back name so now in the name i have the request parameter value what i want to do is now pass this name to the JSP how do i do that the way we do that is by using something called request attributes in the request you can put certain things as attributes and those attributes would be available to the JSP so in the servlet what we would do is we would put an attribute into the request and in the JSP we would take the attribute from the request and show it in the page you have to differentiate between a parameter and an attribute get parameter is what you are passing in here so the parameter is what is passed between the browser and the web application server so from the browser the parameter comes in to this servlet the servlet takes the parameter and put it as an actor buuuut into the request so that the JSP can see it how do I put it as an attribute so you can say request dot set attribute the name of the attribute I will use the same name name and then you can put in a value so the value output in is name as well so now I am setting an attribute into the request what's the name of the attribute its name now in the JSP once I have put something in the request put an attribute in the request and I forward it to JSP the attribute would be available in the JSP let us directly refer to that attribute in here the way you take the value of the attribute is by using dollar open place name and close place that's how you access the name in the JSP let's now reload the page and see what comes up there you go you three localhost colon 8080 name is equal to rithika my first JSP rithika that whatever you pass in here would be printed out in here so my face JSP in 28 minutes there you go in this step we actually passed in a parameter a request parameter from the browser to the servlet and we also passed it from the servlet as an attribute as a request attribute to the JSP and MD JSP we used something called expression language this particular thing dollar open brace and the close brace is called an expression language the expression language is used to dynamically pick up content from request session and other things we will talk about expression language a lot more in further steps in the next theoretical chapter let's learn something about the JSP so we will talk about scriptlets and expression language as we discussed earlier a JSP is nothing but a servlet what we were doing in the login servlet is we were redirecting to this JSP and actually internally this blog indoor JSP would be converted into a servlet everything that you can do in a servlet you can also do in a login dot JSP you can actually write a lot of Java code in the JSP this is not really recommended stuff but it's good that you know it's possible so let's write some Java code in the JSP the way we do that is by doing something called scriptlets in a JSP anything that you write in within these two things is called a scriptlet so let's try let's do a system dot out dot println in here system dot out dot println dummy excute the request again and let's see our console in eclipse you'd see that whatever we have put in here is being printed so if I change this to dummy 2 and refresh you'd see that dummy 2 is printed to the concern that's very good so you can write Java code in the JSP this is called a scriptlet and even things like I would want to let's say get the request parameter so let's say I would not want to print dummy 2 but I would want to say request dot get parameter what is the parameter that we are passing in name let's see what happens now sir refresh I am passing in the name as in 28 minutes what would be printed on the console in 28 minutes because that's the request dot parameter there are few implicit things available like request session request is one among them so we can use request to get the parameter name so what we are doing in here is writing a lot of Java code I mean even you can even do loops int I is equal to zero I mean anything that you can do in Java you can do it in here let's print current time so Java dot util dot date date is equal to new Java dot util dot and if I want to print the value of date I can also do something like this in HTM will be used div to format code so I'll use a div in here div / div and say current date is and I want to print the value of the variable date we can use a script late expression to do that so I want to print the value which is returned by date so this is how I can do that so what we have done is we have created a variable called date and I am doing current date is dead let's refresh and see what happens so you can see that current date is Thursday December 31 10:56 is d that what is printed in here in this particular div you can even do import in here let's say I remove the Java dot util from here in Eclipse you can do a control space and it shows the options I want to use Java dot util you would see that in the first line or import is added in similar to a Java import in a JSP you import using page so at page import is equal to whatever classes that you want to import the same rules which apply to importing in a Java class applies to the importing in a JSP what we are seeing effectively right now is the fact that in a JSP you can write a lot of Jai Java code this is called a scriptlet here we are using something called a scriptlet expression this piece of thing is called an expression language now you know what is possible you can write Java code in a JSP but JSP is a view you should only show information you should not have any business logic the moment you have a lot of Java code in a JSP a lot of business logic tends to creep in and to avoid it we will not use any Java code in any of our examples in the JSP we will not use script lets neither we would use script let expressions all that we would be using is things called en expression language which is things like this dollar open place and we would use something called a STL it's a set of tag libraries standard path libraries which we would be using we will not use scriptlets and scriptlet expressions in this particular course neither do we recommend to use scriptlet in any real world application scriptlets is a very very bad practice and we would recommend to avoid using scriptlets in all the web applications the best way the best place to put in your business logic is in your business layer this servlet controls the flow and the JSP is of you so in the view you would not have any java code all that you would need to do is to take something and show it and that kind of things can easily be easily be done by using expression language and also jst that is a little bit of theoretical background on e l scriptlet and scriptlet expressions now that you have this knowledge you are ready to go into step 4 as you already know the code for all the steps is present in github in the repository in 28 minutes Java Web Application step by step we are now looking at step 4 in this step we want to add another gate parameter password and also discussed about the disadvantages of using get requests I go to the login servlet now I would want to be able to accept another parameter by the name password so along with the name I would want to also accept another parameter called password what I'll do is I'll instruct creating a variable name I will remove that and directly put request dot getparameter name in here so I will remove this line of code so now there is required or set attribute name comma request dot getparameter similar to that I would want to be able to access a parameter called password so requested set attribute password and how do I get the password from the request as well so password and now I can pass this value in in addition to name I can say another parameter how do you pass in the second parameter the way you pass in a second parameter is by putting an and and the second parameter name so password is equal to sum password and this sum dumby value I am passing in make sure that you are typing in HTTP colon slash slash as well so the entire URL is HTTP colon slash slash your webserver name colon port name the first parameter name is equal to in 28 minutes the second parameter password is equal to sum password and these two parameters are separated by n and the parameters are separated from the URL by question mark this is the URL format now I will type this in and there is nothing changing in here because we only added the request attribute password but we have not taken it and shown it in the JSP so let us do that as well so let's quickly say my name is name and password is dollar password once I do this and I would now refresh the page you would see that my name is this and the password is some password I will do a right click inspect element to see what are the parameters which are passed I go to the network tab and reload now you would see the get parameters the request URL is localhost 8080 name is equal to in 28 minutes and password is equal to some password and also you would see in the param there are two param name and password that are being passed and the response that we get back is the content from the JSP in the JSP we are using il to replace the values and we are creating the entire HTML in the js HTML is written back to the browser and the browser displays this in here the important thing in here is for something as sensitive as a password if you are sending it as a get parameter it is sent in the URL Internet is basically a huge number of routers and computers tied together whenever you access a website let us say access Google comm actually the request for that particular website would pass through n number of routers so anybody in the router can see the URL that you are passing in so if you use get parameter to pass my password any of the routers would be able to see what is the information I am passing in and that's not really secure because anybody from then on can use the password that I am sending in to fire in another request if the parameters are passed inside the URL itself that's not really a secure way of doing it and in gate that the only way you can pass in parameters and that is the reason why there is another HTTP request method which is present which is called post we will discuss that more in the next step until now we have passed in a couple of request parameters name and password and we saw that this is not a really secure way of doing it because all the routers and probably the Internet service providers would be able to see what information I am sending as part of the URL we can use a form and create a post request to send information more securely it's not really completely secure because if we want to be really secure we would need to do something called HTTPS and a lot of things like that but for a start using a form and using the post method is much better than sending parameters as part of the get request so let's try and shift towards using a post request we'll create a form first as a first step we would create a form so how do you create a form in HTML the way you'd create a form is by using a tag called form and in the form you have to specify the action so who would handle this form so the form requests we would want to send it to login dot do because login dot do would handle this particular form in this form I would want to initially add in just the name I will not worry about the password initially so I'll just say enter your name and to accept the value which is entered in I would create a input element so the input element I would want to accept some input element so I would type would be text and I would need to give a name to it the name that we would give is name so I am creating an input element with type text and name is name so now enter your name and there is a textbox that's what we have created until enough so input type is equal to text and name is equal to name and next we would need a submit button so input type is equal to submit so what we have done is we create a small form in the form I have put in the action as slash login dot do because I would want this particular request to go to the login servlet so when user click Submit who do I want to handle this request I would want the login servlet to handle this request or action is equal to login dot do and you see that enter your name type is equal to text and then I am creating a parameter name so I am creating an input text with a name name and also I'm creating a submit button when submit button is clicked this particular form would be submitted so let's go ahead and try and see what comes up when I type in it says enter your name and the name which is coming in is submit query I mean I do not like that so you can customize that so you can say value is equal to login or submit whichever way you would want to so now enter your name and login I'll remove this text my name is dollar name and password is password because I don't need it anymore we'll get that input from the user in the textbox let's refresh the screen so now you have enter your name and you have login now I would go and enter my name in here let's say I enter Rangga key and do login what is happening in here is once I enter a name and press login you would see that actually the request parameter is sent as part of the URLs even now even though we created a form it's still creating a get request so let's check that up again so in the network tab let's go ahead and let's type in a name ranga kay and press login and you would see that the request which is sent in still is a get request so even after we created the form the request which we are sending in even now is a get request and not really a post request how do I really make this request a post request the second thing you would observe is also that the parameter name so whatever I am entering as value in here is passed as the parameter so it's passed in as with the name which we gave it and also the value which we are giving in as a parameter so this is good I mean the value is getting passed that's very good but the thing which we don't like is the that is getting passed as part of the URL as a get parameter we would want to make it a post parameter how do we do that the way we do that is by using a method on the form the method we want to use is post now I would go and now I would actually go to login door two and do a refresh the page is loaded up now if I look at the response which came in it has a method of post so if you look at the form it has a method of post so it's the latest code which is coming through so now I'm patting in my name Rangga k and pressing login you can see enough that we are sending a post request I mean if you look at the method in here post request I mean we are getting an error we are getting a server error method not allowed that's basically response status 4:05 which says the post method is not allowed on this particular servlet so what this error is telling us is that on this particular servlet login dot do the post method is not really alarmed why is it so let's look at the code in the login dot do servlet which is login servlet we only have a do gate method we do not really have a post method so we need to handle the do post as well how do we do that we will take care of creating a do post and doing more with it in the next step so in this step what we have done is we have created a very very simple form so we created a form we have an action login do and inside the form we have a text field with the name name and we have a submit button with the name login and when you submit this form we are sending a post request and if you see the content of this particular post request in the parallels you would see that inside the form data we are sending name wrong a case so whatever we have inputted in the text box is going as part of form data earlier when we send the name we were sending it as part of the request URL now we are sending it as part of the form data so we are sending the name as form data using a post method to login dot do but the thing is right now the login dot do is not good enough to handle that request in the next step we will enhance the login dot do servlet to handle this do post requests as well move on to the next step you want to make the HTTP method post acceptable by the login servlet let us go to the login server login servlet if we see it right now it has a do get method it is doing it request dot set attribute I don't need these anymore because I am NOT getting them as part of the gate parameters so I will remove these two lines of code so all that they do get is doing right enough is it forwarding it to the login dot JSP so if I run this right now when I do a login dot do there won't be a problem it would just be loading up the form that we have created I entered in my name I would get an error four or five HTTP method post is not supported so how do I now get the post method to be supported let's get started so the first thing I'll do is just put in something in here do instead of do gate it's do post as simple as that and instead of redirecting it to the login dot JSP I will redirect it to something called welcome dot JS I do not want to redirect it to the same page login once user enters a name and comes in we would want to send him to a different JSP and what's the fun in showing the login page again right so let's create a new JSP I'll go to the login George ASP make a copy of it and call it welcome dot JSP now we have a welcome dot JSP so let's not worry about everything in here title welcome we do not need a login form so I will delete this form and we don't need the import also we are not using the import anyway in login as well I'll go ahead and delete that ctrl D is the shortcut for deleting something in Eclipse will delete the complete line I have a title body I will just say welcome for enough we want to actually get the name and display in in here but for now we'll just show welcome so now what I will do is I'll reload the login dot do page and it says enter your name I'm going to enter ranga k aha there you go a welcome page came up and also if you look at the request which was sent it is a post request and the form data contained name so name is inside the form data but if I look at the header the request URL does not contain name and the request method which is used is post and the status which came back is 200 that means the request went through fine so what is happening now is this JC which we have created welcome dot JSP is working in the do post we are actually redirecting to the Welcome JSP that's very good so that's your first successful form we have created a form log in dot JSP and in the form we put the action in as login dot do they buy it sending a post request to this method and then we directed it to the Welcome dot JSP we are not really displaying the name yet but at least it's going to the JSP now next we would start displaying a name here how do we add the name is the same we need to just add an attribute request dot set attribute what is the name we want to use it's a name so I will put it as name and we need to pick up the parameter from the rig whether it's a guest get parameter or a post parameter there is no difference in how you would get it it's still a parameter for a request so you would still use get parameter so I am saying get parameter name and set it as an attribute I've put it into the requester the thing came in the form data they do post accepts it it set it as an attribute name into the request now I will need to take the attribute in the JSP and show it so I now need to take the attribute from the JSP and show it how do we do that do you remember it it's dollar we are using expression language dollar open place close place and between them the name of the parameter welcome dollar name is it as simple as that let's reload the page login dot do if you look at it right oh we are sending a get when you put a enter in here when we refresh this page we are sending a get and VHS ending login dot do and if you look at the parameters they would not be anything which are same now I would go ahead and enter Rangga key in here so I would not press login you see that another request is created which is post and it's going to login dot do in the parameters name ranga k is sent and you would see that the JSP came back with welcome ranga k so the response which was sent if you look at it contains welcome ranga case so instead of the name we sent in wrong okay so now I can enter any name I can say in 28 minutes let's say and in welcome in 28 minutes the good thing is if I press ENTER also it would work and you can look at the request and the response method I would like you to take a pause in here and look at the code in detail take a pause the entire code for this particular step until the step is available on github in the code step six dot NB so in 28 minutes Java Web Application step by step and code step six dot MD if you go in there the entire code for this example is present so you can take the code including the login dot JSP and the welcome dot JSP so you can take the code run it and make sure that you understand every bit of it also I recommend you to play around with it try to change certain things and play around with it and see what you can learn from it good luck what is the use of login form which does not accept a password let's try and add a password to this in this step let's do it a little quickly so what we want is this is name and we want to have a password field as well so I'll say password and I would need to create a text field to accept the password in html5 there is a type called password so I use that type password and I'll also give the name as password because the name of this particular field is also password so its type is password because when I type something in in a password field it will not be visible and the name which I am giving to it is also password so now I have a password in here now the first step let's actually just display the password ideally this should not be done because I mean why do you want to display a password on a screen so not really good thing to do but just to say that we are able to pick it up let's add it to the welcome dot JSP as well welcome and your password is dollar so there you go now this is so simple to add in a field now if I go and refresh the screen login dot do you see a name and a password and I type in name as in 28 minutes and I will pass I will say some pass word and press login aha bye folks ask me if it wants to if I want to save my password I'll say no and the message which I get back is welcome in 28 minutes and your password is some password ideally you should not do this you'll never display a password on a website but we just wanted to make sure that we are able to get the password correctly now now that we added in the password let's quickly add in some validation for the password and make sure that a user is valid before he comes in so that two kinds of flows possible one is a valid user right so there's a valid user he logs in and that user we would want to send him to the welcome page so valid user with the right password we want to send him to the welcome dot JSP or and it should be AB and a invalid user what do we do with him invalid user I mean if the ID and password is invalid what do we do we send him back to the login page right that's basically what we do you would sending map back to the login page that the functionality that we would try and develop right now so if it's a valid user will go to welcome dot JSP and if it's an invalid user we'll go back to login dot JSP what we would want to do is to find out if a user is valid or not for that I need to have a service what I will do is I'll create a new Java class so I will call it new class and I will say user validation service and say finish and the user validation service will have a method so it will accept it's a public method and it would return a boolean whether the user is valid or not so it will say if a user is valid or not and the name is user is user valid and it accepts two input string user and string enough I will have one set of user ID and password which is valid so I'll say if user equals in 28 minutes and password dot equals dummy returned through I will say let's assume that this is the only set of valid user ID and password in all other situations we are returning a false back this is a very simple service actually this would be talking to some authentication service usually which is in a database or which is really a authentication system to find out whether the user ID and password is fine but here because we are starting with web application development we created a hard-coded simple user validation service this validation service it accepts if it is if it's in 28 minutes or and dummy if the user ID is this and dummy then it's a valid user and any other user for this particular system is of invalid sis user so this is a quite a simple validation service that we built in now we would want to make use of this in the login servlet so what we want to do in the login servlet is in the post method I'll do a right click refactor and extract local variable and I give it a name I am getting the name from the request parameter as well as I will get the password as well I'll call this path so all we had all we are doing is we are taking from the request and putting it to a variable I am putting it over variable so that I can pass it to the login service method so we have actually created a user validation service so what i will do is i'll create an instance of the user validation service in here so i'll say private user validation service is equal to new user validation service i have treated in of the service I would call the service from here service dot is user valid having to pass in the name and the password what does it return it returns if the user is valid or not so if is user valid if user is valid what do we want to do if user is valid we want to send him to the Welcome JSP that's what we decided earlier so if user is valid we'll send him to the Welcome JSP else what did we want to do we wanted to send him back to the log so let's go ahead and do that all that we have done in the last few steps is we created a user validation service the user validation service has only one set of valid user ID and password if that's met then it returns true otherwise it returns false and in the login servlet we created an instance of this part service and we are now using this particular service to validate if a user is valid if the user is valid we are sending him to the Welcome J's he has entered the correct user ID and password so he can go to the Welcome dot JSP otherwise we are sending him back to the login dot JSP let's see if this particular cou piece of code is working I will take the user ID from here in 28 minutes and also I will take the password from here dummy and use it and see if it's working fine aha that's good I am going to the Welcome JSP and I can see the welcome screen in the welcome to our JSP I am printing the password I don't want to see the password anymore on the screen so let's remove the password from the Welcome dot JSP so in the welcome to our JSP I don't need the password anymore so let's just say welcome username so let's do a refresh and it's only printing welcome in 28 minutes that's really good so login dot do I type in in 28 minutes he carefully with the case because we have actually made a case sensitive thing so be careful with the case of into engagement so you copy in in 28 minutes and the password is pas s oops not PS s it's D u mm Y and press login you'd go into the Welcome page let's now apply with a invalid user ID and password so in 28 minutes and some other password login it comes back to the login page so if I enter an invalid user ID and password it takes me back to the login page that's really good but I would really like to see a message in here I would want to see a message which says something is wrong you have done something wrong you entered of invalid credentials something of that kind needs to be printed in here so let's add that functionality in to so we want to add a message what message do we want to add we want to add a error message so how do we send that to the JSP from servlet if I want to send something to the JSP one of the options is requests so request website attribute error message what is the error message for now I will just hard code it in here invalid credentials we have set the attribute invalid credentials in here but we also need to show it on the login dot JSP let's create a paragraph P and let's show the error message in here oops not right dollar thing which we used is error it's case sensitive so be very careful with it and also I'll put a font color is equal to red just to show that it's an error message I mean this is not really perfect HTML but we'll work on it very soon so one color is equal to red error message and the username and the password let's see what happens now login dot do I enter in 28 minutes as the name and some wrong password aha there you go invalid credentials is coming in right enough so now a type in in 28 minute and the correct password welcome in 28 minutes that perfect so now if I enter the wrong password invalid credentials if I enter the right user ID and password are be logging in that's really cool so you have actually implemented your first real login form using post right now in the next step we would further have this functionality
Info
Channel: in28minutes Cloud, DevOps and Microservices
Views: 308,906
Rating: undefined out of 5
Keywords: Servlet LifeCycle, Tomcat, Jsp Servlets Tutorial, in28minutes tutorial, web, jsp, in28minutes, servlet, Karanam, HTTP Request Response, Request Get Method, JSTL, java, Request Post Method, Session vs Request Scopes, Ranga, interview, java (programming language), rithus, Maven, Java Web Application Tutorial, Rao
Id: Vvnliarkw48
Channel Id: undefined
Length: 89min 47sec (5387 seconds)
Published: Sun Jan 10 2016
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.