Course Hive
Search

Welcome

Sign in or create your account

Continue with Google
or
JSP Tutorial #31 - Differences between GET and POST
Play lesson

JSP Tutorial - Java Server Pages Tutorial - JSP Tutorial #31 - Differences between GET and POST

4.0 (1)
11 learners

What you'll learn

This course includes

  • 2.5 hours of video
  • Certificate of completion
  • Access on mobile and TV

Summary

Keywords

Full Transcript

FULL COURSE: JSP, Servlets and JDBC (80+ videos) http://www.luv2code.com/jsp (SPECIAL DISCOUNT) ---- This JSP tutorial series will help you quickly get up to speed with JSP. Download Tutorial Source Code: http://www.luv2code.com/downloads/youtube-jsp/jsp-tutorial-source-code-lite.zip ---- View more videos on the playlist: JSP Tutorial: https://goo.gl/fFVMrj Closed-Captioning and English subtitles available for this JSP Tutorial. ---- Follow luv2code for more JSP tutorial: Website: http://www.luv2code.com YouTube: http://goo.gl/EV6Kwv Twitter: http://goo.gl/ALMzLG Facebook: http://goo.gl/8pDRdA --- If you liked my JSP tutorial, then join my mailing list: Get exclusive access to new Java tutorials. - http://www.luv2code.com/joinlist --- Questions or problems about this JSP tutorial? Post them in the comments section below. --- Want to suggest a video for my JSP tutorial? Leave a comment below. I'm always looking for new video ideas. Let me know what video you'd like for me to create. --- Premium JSP Course Need More Details on JSP? - See my Premium JSP and Servlets course (80+ videos) - http://www.luv2code.com/jsp --- JSP Tutorial Transcript Hey. In this video, we're going to discuss the differences between GET and POST. Well, so far, we've learned how to read form data both with JSPs and servlets, and we sent data over using the GET method. Now, you also may have noticed that there's a POST method, and you wonder how that works and how it's different from the GET method, so we'll cover all the gory details of it here in this video. So just as a recap of what we've seen so far, we've sent data over using the GET method, so we have our form action, and we have method="GET," so that's the HTML form. Then, in our JAVA servlet code, we have to override the appropriate method. In this case, we have to override the doGet method, because they're passing in a GET request. Here, in red, we have a request.getParameter. That's for reading the form data. We've seen this before, just kind of recap. Now, let's move forward a bit, and let's look at POST method. To send data over using a POST, in our form, we say form action, and we have method="POST". Now, in our servlet code, we need to override the doPost method. Now this doPost method has the same params as doGet. It has a request and a response. For the doPost method, you simply read the form data by saying request.getParameter, so the exact same method call to read form data using POST. Now, when data's being sent using the GET method, the form data is actually appended to the end of the URL as name/value pairs, so here, we'll have a URL with a question mark, and then we'll have field 1=value1 and, with an & symbol, field2=value2, with another & symbol and so on. That's basically how form data is sent using a GET method. Now, sending form data using a POST method, the form data is actually passed in the body of the HTTP request message. So the request message has a body section, and the name/value pairs are included inside of the body of the POST method, so you won't see it in the browser's URL. All right, so you see all this stuff and you're like, "Okay, well, which one should I use?" A recap. The GET method here is very good for debugging, because you can see the name/value pairs right there in the URL. You can also manually change them if you want. You can also bookmark the URL, and you can also email it. With the GET method, there's a limitation on data length, and it varies between browsers, so you just need to be aware of that. You're normally safe with about 1,000 characters. Now, with the POST method, you can't really bookmark or email the URL, because the URL doesn't contain the data. Remember, the name/value pairs are sent in the body of the request message. A really nice thing about the POST message is that there's no limitation on data length, so if you have a very large form with a lot of fields, you can send as much data as you want to. Also, the POST method is very good for sending binary data, and you're probably wondering, well, what type of binary data? Well, if you do like an email program and you do a form attachment, you can attach a binary file to the form and then submit it. So that's one use case there for the POST method. My normal recommendation for non-sensitive data, you can use the GET method. It's very good when you're first starting out with your application for debugging and so on. However, if you have some sensitive data, then I'd recommend that you use POST data. Here, sensitive means that the POST method can encode some of it. It doesn't do any real heavy encryption, but it will kind of encode it, so this is more of security by obscurity. For full security, for full encryption, you would need to implement the secure sockets layer. [Snip] for complete transcript of JSP tutorial, select "More ... Transcript"

Course Hive

Continue this lesson in the app

Install CourseHive on Android or iOS to keep learning while you move.

FAQs

Course Hive
Download CourseHive
Keep learning anywhere