JSP Tutorial #22 – JSP Forms Checkbox Part 2

0
70

FULL COURSE: JSP, Servlets and JDBC (80+ videos)
(SPECIAL DISCOUNT)

—-

This JSP tutorial series will help you quickly get up to speed with JSP.

Download Tutorial Source Code:

—-

View more videos on the playlist: JSP Tutorial:

Closed-Captioning and English subtitles available for this JSP Tutorial.

—-

Follow luv2code for more JSP tutorial:

Website:
YouTube:
Twitter:
Facebook:

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

All right, so lets go ahead and move in to Eclipse. And what we’re going to do, is this project will work similar to the previous one. We’re actually going to start with our student.form-html. We use that as a starting point, and then we’ll just add new features in here for the check box.

So the first thing I’m going to with student.form-html is I’ll do a right click, and I’ll choose copy. And then again, I’ll do a right click and I’ll choose paste. And now, the new name here, we’ll call this student-checkbox-form.html, so that’s the new name for it. And once you’re happy with the name, you can click OK. Now let’s go ahead and open up this student-checkbox-form.html.

So the first thing we need to do here on line seven, we need to change the JSP that we’re going to send the data to. So here I call it student-checkbox-response.jsp. That’s the new jsp that we’re going to create a little later in this video.

Let me expand my window here, and also let me just get some extra white space down here so I can have some room to play, add another line break, and now I’ll go through and start entering in the information for my checkbox. So here I’ll say, input type=”check box”. Name=”favorite language”, value=”java”, and then we put our label out to the side, java. So again, very similar to radio buttons, the only thing that’s different here is the input type=”checkbox”. And now what I can do is I can simply repeat this process for all the other languages.

So I’m just going to speed up the video here for a bit while I just do a copy paste and do a quick update for those other languages. All right, I’ll just save my file. Okay, this looks really good right now. So, basically I have the four languages here, input type of checkbox, and it works out really well. So our html form for the check boxes is pretty much taken care of for right now. Good job.

All right, so lets do a similar thing here for our response page. So again, we’re going to use the student-response.jsp as a starting point, and then we’re going to customize it. So I’ll simply copy this file, and then I’ll right click and I’ll do a paste for it, and the new name that we’ll give here of course is student-checkbox-response.jsp.

And once you’re happy with that name, go ahead and click okay. So now we have this new file here, student-checkbox-response.jsp. Now lets go ahead and double click this file and open it up. This is the original confirmation page from before, we’ll just add some line breaks here, and I’ll just expand the window so I can have more room to work with. And so what I need to do here, is I need to display the list of favorite programming languages that the user selected. So it’s going to be an html list of data. And I just want to get some more white space here at the bottom. Give me one second.

All right, so I’ll make use of an html tag UL for unordered list. And I’ll put in multiple list items here. But I’ll actually generate these on the fly using a jsp scriptlet. So notice the angle bracket percent, and now I can write real java code. So here, what I want to do is use that request I get parameter, and I want to get parameter, actually get parameter values, because it’s going to be multiple items that are going to be returned, and then I’ll say a favorite language. Okay, good. Now I actually have a syntax error here. Because this method, request get parameter values, it returns an array.

So I need to add the square brackets here for an array on line 14. That took care of that error. So now, simply just need to do a for loop through that array and display list items here.

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

source

LEAVE A REPLY

Please enter your comment!
Please enter your name here