 Hello, everyone. So, in this video, we are going to see methods in servlet using two methods do get and do post. Okay, I'm Professor Dattadri Ghandmal from Valchand Institute of Technology, Sulapur. So, let us begin with this video. What students will be able to understand? Students will be able to differentiate between do get and do post method. We will see to it what is do get and do post. And students will be able to write a program demonstrating the difference between do get and do post. Okay, let us quickly begin with the actual working of this program, how we differentiate do get and do post. We'll come down to eclipse. We have already seen this program in the previous video, where response dot set content type text HTML and print writer response dot get writer, right, and get parameter n where n is that is the data passed from HTML page. This is the n. So, this n will come here and we are going to display welcome name. Okay, let us try to run this program. Okay, it will execute. And in here, whatever name I'll write, I'll write Ankit. So, it will say welcome Ankit. So, this is how the data is passing from HTML page to your servlet page. Okay, so here welcome Ankit is coming. Okay, what if I change some something in HTML? I'll add some more values. I'll take this line. Okay, I'll also ask user to enter password. Enter your name, enter your enter password. Let's enter password. Okay, and here I'll take name equal to P. Okay, so password and the type I'll make it password. Since it's a password type, I'll make it password. Okay, and we'll come down to demo servlet. Here get parameter is welcome name. Okay, we'll keep it all the things same. Let us see what will happen. First of all, stop the Tomcat and come down to your program and run it once again. Okay, now there are two sections. This is Ankit and password I'll write something. So, which is not visible because I made the type as password. When I log in it will go to welcome Ankit. Now what I want is I want I'll change something here. I'll give login authority only to the valid user. I will check whether it is a valid user or not. So here we will write some if else kind of thing. Okay, now here, if he's a valid user then only I'll allow him otherwise I'll say oh you're not a valid user. Okay, let's have something like if if name dot equals we have an equals method. Okay, if name dot equals Ankit will also similarly we will take password. Okay, so here I'll write string pass equal to request.get parameter there we have written P. So I'll take your P and pass dot equals let's say I'll make it admin 123. So password is admin 123. If this is there, then I say welcome. Otherwise else I'll say PW dot print line invalid user. Are you getting so if he is a valid user then only I will give him access otherwise I will not give him access. Okay, so name equal to Ankit and pass dot admin 123. Okay, let us see to it. Okay, now come down to run it once again restart the server. If I write name equal to Ankit and password equal to admin 123 log in. So welcome. Ankit is saying what if I put a wrong password I'll put something else. Okay, invalid user it is saying are you getting so this is how I can restrict access to a particular page in servlet. Okay, now what if I change this is with a get method. Now let us try to understand the difference between get method and post method. Whatever we have done till now we have done it in get method. Okay, the drawback with get method is that if you observe closely here in the URL n equal to Ankit and p equal to some password is visible. So when a user puts a username and password someone can hack your credentials from this URL. So you are passing your actual credentials even if I have put let's say I have put admin one admin 123. If I log in here I can see admin 123. This is the biggest drawback of get method. Okay, to overcome this what we will do we will make this a post method. If I make this post method here this code now should come in post method. Okay, now let us see I'll stop this. Okay, we'll run it once again. Same code we are doing right. So here I'll put now Ankit and password equal to admin 123 admin 123. Okay. Now here welcome Ankit here in URL you can see there is nothing passed that is the biggest advantage of using post method. So when you should use post method when you don't want your credentials to be passed as an URL in get method the credentials are passed as an URL. Whereas in post method the credentials are not passed. Is that clear makes sense. So because what we have done in index.html make this method as post instead of get method. So whenever you want the data to go through URL make it get and whenever you want your data to go not to go from URL then make it simple. Okay. I hope it makes sense. So here in I'll repeat once again in demo servlet that particular code will reside inside do post. Earlier it was in do get. Now I've put my code inside do post. So if you just put your code inside do post it will make the job. That is the difference between. Okay. We'll come back to our PPD presentation. So now let us take a pause and try to answer this question which method passes data through URL. There is one more which method does not pass data through the URL. Just now we have seen it. Just try to recall pause and answer this. Okay. The answer for this is the data which passes through URL is do get and data which does not pass through URL is do post. Okay. Now let us try to understand the difference between do get and do post that is get method and post method. Get request sends the request parameter as a query string appended at the end of the request. So we have seen that it is passed as a URL. Post request send the request parameter is as part of HTTP request to body. That is the difference between get and post. Second difference is it will be displayed in the address bar of a browser. Whereas post method it does not display it in address bar. So here it will go as a URL. Here it will not go as a URL. Okay. Then on restrictions on form data that is ASCII characters are allowed whereas no restrictions on form data binary data is also allowed. So that is the difference between when to use get and when to use post based on the requirement we will prefer to use get method or to use post method in get method the maximum size limit is 2000 characters whereas in post method the maximum size is 8 MB. Okay. So in post you can send more data whereas in get method you can send only limited data. Here restrictions on form length. So URL length is restricted. No restrictions on the length because the data is not passed through URL. So there is no restrictions and remains in browser history and this thing doesn't remain in the browser. Since URL is not passed and data is not stored in the cookies. So you can mostly whenever you want to send credentials important credentials use post method. And whenever you don't want to send any important credentials used get method. Okay. So we have seen the demonstration. We have also seen the difference. I should use should be I think you should be able to do the code now. Okay. These are some of the references which I have used. These are some books some ebooks and e-resources you can go through it. They are good to go through. Okay. Thank you.