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. So let's go and move into eclipse and let's start coding. So the first thing I want to do is actually create a new file. So I'll move down to this web content directory. I'll create a new file. So I'll say new file. And for the actual file name I'll choose cookies personalized form dot html. This will be our html form for personalizing the website and once we're happy with that name we'll go ahead and click finish. All right, so in this file I'll go ahead and just write out my basic html header information and my html body. For the header I'll just go ahead and set up a title real quick. I'll personalize the site. That's my basic house keeping. Now I'll actually go through and build out the form. I'll set up my form I'll say action equals cookies personalized response dot JSP. And so now I'll just kinda build out my form. First off I'll prompt user to select your favorite programming language and I'll set up a drop down list or a select item. So we've seen this before so I set the name equals favorite language and then I just drop in those languages. Java, c sharp, PHP and ruby and again we've seen all this before. Now one more thing you'll need to do with this form is set up my submit button. So I'll move down here and I'll say input type equals submit and then value equals submit. That is basically it here for our form. Just prompt new user form for their favorite programming language and then having our submit button. All right so we can go ahead and save that file and let's just do a quick test on it to make sure it works out. So I'll just choose this cookies personalized form dot html and I'll just say run on server. This looks pretty good so great there is our prompt, there is our drop down listing, our submit button, so this part looks okay so far. So moving ahead to step two I need to create another new file. This file is going to be our response page so I'll call it cookies personalized response dot JSP. Once I'm happy with that name, I'll go ahead and click on the finished button. All right, so this JSP basically is going to read the form data and then also create cookies or set cookies and pass them back to the browser. So again I'll go ahead and do my basic house keeping here for the html and then I'm going to set up a scriptlet for my angle bracket percent. The first thing I need to do is read the form data. I'm going to read that form field favorite language that we had in the previous file. Now that I have that actual favorite language, now what I'm going to do is create a cookie. So I'll say the cookie equals new cookie and I give that name value pair. So name of my [inaudible 00:03:27] language and then the value is fav lang. So now I have that cookie created. Next I need to actually set the live span on the cookie. So I'll say the cookie dot set max age. This is the ugly part again remember. You have to give the total number of seconds so I did the math and that's the total number of seconds for one year. Once we have that taken care of, then we simply need to send the cookie to the browser and we do that by doing a response dot add cookie and then giving a reference to that cookie object. That's basically it to the step two of reading the form data and then setting the cookie. So now what we'll want to do is go through and just put our body in here. So this body is mainly just a confirmation just a echo whatever the user entered. So here I'll say hey thanks we set your favorite language to and then we just drop in that parameter information so I use a dollar sign param favorite language. [Snip] for complete JSP tutorial transcript, select More ... Transcript
