JSP Tutorial #11 – JSP Expressions



JSP Tutorial #11 – JSP Expressions

JSP Tutorial #11 - JSP Expressions

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

Hello. In this video we’re going to learn how to use JSP expressions. In JSP there’s actually different types of scripting elements. There’s three actually: JSP expressions, JSP scriptlets, and declarations. Now, what we’ll do is we’ll actually have a deep dive on each one of these topics in separate videos, but I wanted to give you just an overview real quick.

A JSP expression is basically a small java expression that you can include in the page. They syntax is angle bracket, percent, with an equal symbol, and we’ll see a lot of that in this video. There is also what we call a JSP scriptlet. A JSP scriptlet is simply an angle bracket, percent, and then you add some java code. You can add one to many lines of java code, and we’ll see that in the following video. Then finally, there’s a JSP declaration. This is angle bracket, percent, with an exclamation point. Here you can define an java variable or method. Again, we’ll do a deep dive on that.

This next slide here is on JSP expressions. Basically you can compute some type of expression and the result of that is included in the HTML page that’s returned to the browser. Here is an example. We saw this from one of our previous videos, actually the previous hello world video. In your JSP file, you can say, “The time on the server is,” and then you can add an expression. Again, remember angle bracket, percent, with an equal symbol, and we can place a java object there. Once this is processed by the server, then the generated HTML is simply the two string version of that given date object.

Let’s take a look at some more examples of using JSP expressions. In this next example I’m going to show you how we can convert a string. Here I have this new string, hello world. Then I can say dot to upper case. I’m going to basically convert this string to all caps, or to all upper case, and the result of that will be included right here in the page. That’s for strings and objects. You can also make use of mathematical expressions. Here I can multiply a value, 25 times 4 equals … You can put any math expression in there that you’d like. You can also have Boolean expressions. Here I could say, “Is 75 less than 69?” It will give me a value of true or false. That’s an example, here, of using JSP expressions. We saw objects, mathematical expressions, and also Boolean expressions.

Okay, great. Let’s move into Eclipse and let’s try this stuff out. I’d like to continue to use the same project from the previous video, JSP Demo. I’d like to move down to my web content folder. What I want to do here is actually create a new file. I’ll just right click, I’ll say, “New file.” For the name of this file, I’ll simply call it ExpressionTest.jsp. Once your happy with that file name, you can go ahead and click the finish button. Okay, great. We have a very basically file here, actually an empty file. We need to add something in it. Let’s go ahead and start off with our basic HTML. I’ll set up my body tag. Now I’ll go ahead and type out that first bit of converting a string to upper case. Now what I’d like to do is add a JSP expression. Again, angle bracket, percent. Here is say, “New string, hello world,” and I do a dot and I get the code completion here and I’ll say dot to upper case. I’ll select that item there.

It’s kind of cool. Eclipse can kind of help you out with some of the code completion there in a JSP file.

[snip] JSP tutorial transcript select “More … Transcript”

Comments are closed.