JSP Tutorial #29 – Read HTML Form Data with Servlets – Part 1



JSP Tutorial #29 – Read HTML Form Data with Servlets – Part 1

JSP Tutorial #29 - Read HTML Form Data with Servlets - Part 1

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 learn how to read HTML form data with servlets. We’ll start off with the student-form.html. That’s going to be our HTML form. We’re going to gather the student’s first name and last name. They’ll hit the Submit button. The request will go across to our servlet, StudentServlet.java. Our servlet will process the request, and then send back a response. That’s the basic idea here of having a servlet read form data.

All right. Let’s walk through this step by step. The first step is building the HTML form. We’ve seen most of this before, so we start off with our form. Now, the action equals StudentServlet, so that’s the name of the servlet that we’re calling. Then we set up method equals GET because we want to make use of a GET request to that servlet. Then from there, we simply set up the HTML form fields. We set up First Name field, Last Name field, and also a Submit button. Again, we’ve seen a lot of this stuff before. Just a basic form that we’re setting up for our example.

The one thing that’s different here or unique that I want to point out here is that since this form is going to send the data using method=GET, this actually calls the doGet method in our servlet. Method=GET will call the doGet method in your servlet, so you have to make sure that you override the appropriate handler method or make sure you override the doGet method.

Now, the next step here is reading the form data in the servlet. At the top, I showed you the first name and last name. At the bottom, this is the actual servlet code. Again, we override the appropriate method here, doGet. They pass on a request. The request object has your form data or it contains the form data. Here, I simply use an out.print line. The student is confirmed. Here I say request.getParameter. That allows me to read form data. Request.getParameter on first name, and then request.getParameter for last name. Those parameter names map to the actual HTML form field names.

That’s basically it here for our servlet example. What we’re going to do in the next video is we’re going to move into eclipse. We’re going to get some hands-on practice. We’ll actually build this example from scratch, so I’ll see you in the next video.

End of JSP tutorial transcript.

Comments are closed.