JSP Tutorial #17 – HTML Forms Overview



JSP Tutorial #17 – HTML Forms Overview

JSP Tutorial #17 - HTML Forms Overview

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

In this video, I’m going to show you how to make use of HTML forms with JSP. We’ll actually cover the following topics. I’ll first start off with the review of HTML forms, then I’ll show you how to build an HTML form. Next, we’ll learn how to read the form data with JSP. All right, a lot of good stuff.

We’ve all used HTML forms before. If you’ve gone to any website where you had to log in with a user ID and password that information was entered via an HTML form. Also, if you’ve gone to any travel site and booked an airline trip or a hotel reservation, again, all of that data was entered through an HTML form.

What we’re going to do here is we’re going to learn how to build an HTML form to read student information. We’re going to prompt the student for their first name and last name. They’ll enter it into a text field and then once they enter that data they’ll hit the submit button. Once they hit submit that data will be sent over to a JSP page for processing, so we’ll have a JSP page will read the form data for the first name and the last name, and we’ll send back a confirmation page to the browser. I’ll show you how to put all of this together. We’ll start with the form first and then we’ll move into the actual JSP development. All right, let’s get started.

Here’s the coding here for the HTML form. Again, we want to have an HTML form for the first name and last name, along with the submit button. When you build an HTML form you start off with the form tag and then you specify the action. You’re basically telling the system where to send the form data, so we’re telling the system here, “Send the form data to studentresponse.JSP.”

Next, we set up our text fields for first name and last name. For a text field we have input type equals text. We gave name equals first name. That name’s very important. We’ll need that name on the server side. We do a similar thing here for last name. Input type equals text. Name equals last name. Finally, for our submit button we set up and input type, so we say input type equals submit, and then we give the value of submit. The value portion here is really just the label that you’ll see on the submit button, but once they hit the submit button then that data will actually be sent over to the appropriate JSP page for processing.

Here’s the coding here for reading the form data, so whenever we read the form data with the JSP it’s very important that we need to know the names of those HTML form fields. I have these HTML form fields here on this slide just for reference. At the bottom, in the JSP file, we simply want to say the student is confirmed and then we want to display the student’s first name and last name. We read the form data by saying request.getparameter then we give it that form field name, first name. Then to read the last name we do a similar thing, request.getparameter last name. We place all of that inside of JSP expression with angle bracket percent with the equal symbol and that will allow us to read the form data in JSP.

Next, here’s an alternate syntax for reading the form data. You can make use of this dollar sign curly brace, and then you can say param.formfieldname, so a simpler way of writing this page is the student is confirmed and then we simply say ${param.firstname}, and the similar thing here, ${param.lastname}. This is really just a shortcut method. It’s only used for displaying form data, so it’s really just a shorthand simpler way of writing the code. But if you need it to read the form data and maybe a scriptlet or something then you’d have to resort back to using the request.getparameter, but as much as possible I’ll try and make use of this shortcut method in our confirmation pages.

[Snip] for complete transcript of JSP tutorial, select “More … Transcript”

Comments are closed.