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:
If you liked my JSP tutorial, then join my mailing list: Get exclusive access to new Java tutorials.
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)
JSP Tutorial Transcript
Okay, so let's go ahead and move into Eclipse. And what I want to do is continue to use that Servlet demo project that we had in the previous video. And the first thing I need to do, as far as my step one, is creating the HTML form. I will move to this web content directory, I will do a right click, I will choose new and file.
The actual file I am going to create here is called student form dot html. Once you are happy with that name, you can go ahead and click on the finish button. This will give us a very empty file here or blank file and we need to add some data here. I will first start off with my normal HTML housekeeping. HTML and then the body tags and that's the basic stuff there.
And now what I need to do is go ahead and create my HTML form. With this form, we are going to have action equals student Servlets, or calling it student Servlet, and we are going to use the method equals get. That's the HTTP method, that's going to map over to our do get method in our Servlet.
All right, so now let's go ahead and set up our HTML form fields. I will start off here with the first name, input type equals text, name equals first name. And then I'll do a similar thing here for last name, I'll say input type equals text, name equals last name. So again remember, these form field names, these are the actual names that you'll use in the actual Servlet code for reading that data. So you have to make sure that you use the same names in the Servlet code. I'll just copy this line break, put it down here. And then finally, I'll wrap it up with a submit button. Input type equals submit, value equals submit. And that's basically it for our HTML form, so it's going to send data over to the student Servlet and going to use the method of get. All right, so this looks really good. Good job so far.
All right, so I'll save this file. Now the next thing we need to do as our step two is actually creating the Servlet. So I'll move up to this Java resources directory. I'll move down to the package that I created in a previous video, our Servlet demo package. I'll simply right click, I'll say new, Servlet. The name I'll use for the Servlet is student Servlet, so we'll use the same name that we reference here in the actual HTML form. And once we're happy with this, we can go ahead and click the finish button.
All right, so over on our far left side here, we have this new student Servlet dot java that was created by Eclipse and it generated a lot of good code for us that we can start with. It helps jump start our development process. Up top, we have this at web Servlet annotation, slash Servlet, so that's basically the name that we'll use for calling it Servlet. We have our Servlet class that extends HTTP Servlet. We've seen all of this stuff before.
Let me just clear out some white space here. And this is our do get method. This is the method that gets called when the actual HTML form submits the data because they are using the method equals get. All right, so let me clear out that auto generated code, and let me write my own code. And just like I did before, I always like to write some comments, just to tell myself what I need to do. So the first step is I need to set the content type. And then step two, I need to actually get the print writer. And then finally, step three is where I do my real work. This is where I generate the HTML content.
All right, good, so this is my game plan as far as what I need to do, my work. All right, well let's go ahead and dig in. Let's start with step one. Set the content type, I use response dot set content type.
[Snip] for complete transcript of JSP tutorial, select "More ... Transcript"