JSP Tutorial #10 – JSP Hello World



JSP Tutorial #10 – JSP Hello World

JSP Tutorial #10 - JSP Hello World

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. In this video, I’m going to show you how to create a Hello World program with JSP. The common question is, “What is a JSP file?” Well, a JSP file is simply an HTML page with some Java code sprinkled in, and it basically gives you dynamic content that you can include in your page. In this diagram here, this is a basic JSP file. It has some HTML code, some Java code, you can mix in some more HTML code, and so on. The end result is that you’ll have an HTML page with content that’s generated by some Java code.

All right, so the next question is, “Where’s the JSP processed?” A JSP file is actually processed on the server, so it’s processed on your Tomcat server, your GlassFish and JBoss server. The results of the Java code is actually included in the HTML return to the browser. Here’s an example: We have a web browser. We make a request for a JSP page. It goes across. The JSP page is processed by your server, and then the results of that Java code will generate HTML, and those results are actually returned back to the web browser. It’s returned back to the browser as just plain HTML. In effect, the Java code can generate HTML that goes back to the web browser.

All right, so next where should we place the JSP file? The JSP file goes into your WebContent folder. You create a new Eclipse project, they have a WebContent folder, you place the file there. Then one requirement is that, the JSP file must have a .jsp extension. Here’s an example here we have on the slide. WebContent, helloworld.jsp. It’s just like any other normal HTML file that you place out there, like building a normal website. You can have multiple JSP files. You can place your JSP files in subdirectories, and so on, so it’s almost like building a website, with multiple HTML pages, except for here, we’ll have .jsp files, with that JSP extension.

So you’re probably wondering, “Hey, show me the code.” Here’s an example of the code. Very basic Hello World program. Again, remember, a JSP file is simply an HTML page with a small bit of Java code sprinkled in. Here we have our body, H3, Hello World of Java!, and then the time on the server is, and right here, this is where we have Java code. With JSP, you make use of the angle bracket percent, and inside of there you can put a JSP element. In this case, we’re going to put in what we call a JSP expression.

Use the equals symbol, so angle bracket percent equal, and then we could put in some Java code. This example, we create a new date object. This will give us a current timestamp, and then we include the output of this date object in the page. In effect, it’ll call the toString method on this data object, and include the result of that in this page that goes back to the browser.

I know I gave you a lot of information there. Let’s go ahead and switch over, and look at Eclipse. We’ll write this code, and then we’ll run it within Eclipse. We’re in Eclipse, so the first thing we need to do is we need to create a New Web Project. I’ll go up to my File menu, I’ll say New. I’ll choose Dynamic Web Project. This will bring up the dialog. We can enter our project name. Here, I’ll call it jspdemo. You can give any name for the project, but here I’m just keeping it simple.

Make sure the target run time is set up for Apache Tomcat 8, and you can keep all the other defaults with no problem, and then simply hit the Finish button. What this will do is this will create a new project for us, so we have jspdemo. If we expand this directory, we’ll see that we have a WebContent folder. Right now our WebContent folder is empty. There are no pages that are created.

Here, I’m going to create a new file. Under WebContent I’ll right click. I’ll say New File. I’ll call this helloworld.jsp.

[snip] JSP Tutorial transcript, select “More … Transcript”

Comments are closed.