Today is Wednesday, 11th January 2017

Archive for the ‘Java Server Pages (JSP)’ Category


FAQ: What is the difference between JSF and JSP?

In a nutshell, JSP is suitable for small web projects and JSF is best for large scale enterprise projects.

JSP is an older technology … but it is still viable for smaller web apps. I like to use it for training since it is very similar to PHP. Most Java newbies can pick it up with no problem because it is simple and straight-forward.

Think of JSP as your low-end, economy car. It will get you to your destination but no special bells and whistles. It is ike flying “economy/coach” class.

If you are building a modern, large-scale, enterprise app then I’d recommend JSF. The framework provides data binding, validation, bean support etc.

Think of JSF as your luxury vehicle. It will get you to your destination in style … however with additional up-front luxury costs. It is like flying “first class”.

Hopefully this helps.

 

Share


JSP Tutorial #13 – Java Server Pages Tutorial – Including Files

In this video, I show you how to include files in JSP pages.

Please SUBSCRIBE to my YouTube channel.

 


 

# Video
1 Introduction
2 JSP Overview
3 Setting up your Development Environment - Overview
4 Installing Tomcat
5 Installing Eclipse
6 Connecting Eclipse to Tomcat
7 JSP Hello World
8 JSP Expressions
9 JSP Scriptlets
10 JSP Declarations
11 Importing Java Classes
12 JSP Built-In Objects
13 Including Files

Do You Need More Details?

  • How to read form data with JSP?
  • How to use cookies and sessions?
  • Develop MVC application with JSP and Servlets?
I have a premium course that shows you how to complete all of these tasks.

Read more about the premium course at http://www.luv2code.com/jsp

Follow luv2code with the links below:

– Website: http://www.luv2code.com
– YouTube: http://goo.gl/EV6Kwv
– Twitter: http://goo.gl/ALMzLG
– Facebook: http://goo.gl/8pDRdA

JSP Tutorial Transcript:

Hello. In this video, I’m going to show you how to use JSP for including other files. The common used place for including files is including standard headers and footers. Say for example you’re building a website and you want to have the same header and footer information displayed on every page. You can simply create the header and footer in separate files and include them in your JSP files. All right, so when you include a file you can include either HTML files or JSP files. It’s totally up to you. At the top here, I do a jsp:include and page=”my-header.html”. A similar thing here at the bottom, I can do a jsp:include page=”my-footer.jsp”. That’s it. Very simple, very straightforward.

All right so let’s go ahead and try this out, so let’s move into Eclipse. What I’d like to do is to continue to use that existing project, jspdemo. Let’s move down to the web content folder, and what I want to do first is create those files I’m going to include. First I’m going to create the header files. I’ll say “New”, “File” and I’ll give the file name of “my-header.html”, so that’s the header that we’re going to include. When you’re happy with the file name here, click finish. For the header, I simply want to give the name “JSP Tutorial”, so I’m going to set up H1, and I’ll make the alignment for it to be center. Then inside the tag here, I’ll just say “JSP Tutorial”, so this will be including on all pages for my given website that I’m just making up right now. I’ll go ahead and save this file, so this is our header file that we have set up right now.

Now let’s over and let’s create our footer. So again, on WebContent I’ll do a right-click, I’ll say “New”, “File”, and I’ll call it “my-footer.jsp”. In the footer we actually want to add some JSP coding. Once we’re happy with the file name, go ahead and click finish. For here, for the footer, for every page I want to give the time the page was last modified. Or, we’re just going to kind of make this up, actually. So here’s I’ll just say, “Last Modified” or “Last Updated” and I’ll just drop in the actual date timestamp. That way all of our pages every time a user will visit our website. Now I’ll just hit the save button.

Okay, great. So now at this point, we have our header complete and we also have our footer complete. Now we can go ahead and create our main page that’s actually going to include these files. I move over to the WebContent folder, I’ll do a right-click, I’ll say “New”, “File”, and I’ll call this, “homepage.jsp”. Once we’re happy with the name here, we’ll click finish. On this homepage, what we’re going to do is we’re actually going to include information from the headers and the footers, and also we’ll put some of our regular content here. I do the standard work here for our HTML in our body. Now what I want to do is import or include the header. So I’ll say jsp:include, I give page=”my-header.html”. Now I can enter some regular content that I’ll have on my homepage. Here I’m just going to put in some filler stuff, just some blah blah blah. Just to you know, placeholders here. Then I’ll copy this line x number of times, just to kind of fill it up a little bit. So that’s our content. Let’s go ahead and include our footer. I’ll say jsp:include page=”my-footer.jsp”, because our footer is a jsp file. Again, it an go either way. HTML or JSP, depending on how you want to build out your pages. That’s it. I can go ahead and save this file and then I can go ahead and run it.

All right so I can move over to this file homepage.jsp. I can do a right-click, then I can say, “Run As” and then “Run on Server”. Okay, great. This looks really good. Up top we have our header file that we included, JSP Tutorial. Then we have all of our body, all of our blah blah blah stuff. Then we have the actual footer, and then notice how the footer is a JSP and it included the current timestamp when this page was access. Our site will always look fresh as far as our fresh content. Which is a good thing, right? So good job. In this video I showed you how to build JSP pages by including other files.

Share


JSP Tutorial #12 – Java Server Pages Tutorial – JSP Built-In Server Objects

In this video, I show you how to use the JSP Built-In Server Objects.

Please SUBSCRIBE to my YouTube channel.

 


 

# Video
1 Introduction
2 JSP Overview
3 Setting up your Development Environment - Overview
4 Installing Tomcat
5 Installing Eclipse
6 Connecting Eclipse to Tomcat
7 JSP Hello World
8 JSP Expressions
9 JSP Scriptlets
10 JSP Declarations
11 Importing Java Classes
12 JSP Built-In Objects
13 Including Files

Do You Need More Details?

  • How to read form data with JSP?
  • How to use cookies and sessions?
  • Develop MVC application with JSP and Servlets?
I have a premium course that shows you how to complete all of these tasks.

Read more about the premium course at http://www.luv2code.com/jsp

Follow luv2code with the links below:

– Website: http://www.luv2code.com
– YouTube: http://goo.gl/EV6Kwv
– Twitter: http://goo.gl/ALMzLG
– Facebook: http://goo.gl/8pDRdA

JSP Tutorial Transcript:

Hey, in this video I’m going to show you how to make use of JSP Built-In Server Objects. What Built-In Server Objects, these are given to you for free so there’s no need to create them, you can simply use them directly in your JSP page. We’ve actually played around with some of these earlier, and I’ll show you this on the next slide. Here is the list of the commonly used JSP Server Objects. Starting here at the top with request, it contains information about the HTTP request headers and also form data, we’re going to use this a lot in some of the following videos for reading form data. There’s also the response object for sending back HTTP specific information and we will use this also in the following video on making use of cookies. This one Server object you use already, the out Object, and we use that for our out dot print line in one of the previous videos. Again, a Built-In Server Object given to you for free.

There’s two others here, session, it’s a unique session for each user. You can think of the Session Object as like the shopping cart, each user has their own unique shopping cart, we will use this on the following video. Finally there’s the Application Object, this is shared for all users of a given web app and I’ll discuss various use cases on how to use the Application Object. Just for disclaimer, this is not an exhaustive list, there’re other server objects out there but these are the ones that are commonly used for JSP web apps. Here’s the idea, you have the browser communicating with the JSP, behind the scenes the HTTP protocol, they actually send our request object, this request object contains header information and body information. JSP can perform some work on that information and then send back a response, so we have the whole request response protocol going. In the demo I’ll show you how to make use of the request object.

Let’s go ahead and move into Eclipse, what I wanted to do is continue to use the existing project JSP demo and I would like to move down to the folder your web content because we’re going to create a new file. I just say right click, I say new file. The name I’ll give here, I’ll call it builtin-test.jsp because we’re of course testing some of the built-in objects. Once you’re happy with the name we’ll go ahead and click finish. Let’s expand the window here for a second and I will bring file and start writing some code. Again, I start off with my HTML and my body information. I’ll just set up a header three just to give us a little name here for the page. Now what I want to do is, I want to read some information about the request so I want to find out what type of browser the user is using to access my JSP page. You can access this information using the request object.

So I can say, request.getHeader and then you get the header name of user-Agent. This will tell you the actual browser that the client is using, also it will tell you the operating system that they’re running on. Let me go ahead and add some line breaks here. I want to find out what language the client is making use of in their browser so if they’re using english, Spanish, German, French. Here I say request.getLocale and this will get me the actual locale that the user has set up on their system. We can use this to customize the type of pages we send the user based on their actual locale, like English or German or Spanish. That’s basically it for this very basic demo here. Go ahead and save your file and let’s go ahead and run this program. I move to the file builtin-test.jsp, I’ll do a right click and I’ll say run as and then run on server so the application runs.

Note here request user-Agent so they will tell us the type of browser that’s coming through. Here we’re using this internal browse that’s built-in as part of this Eclipse tool but note it also says that we’re using Mac OS X so we know the operating system and the browser that the user’s running on. Let me copy this information and put it into a different browser, I’ll drop it in the Chrome and I’ll just paste it. I’ll hit enter and so now we get the same information but note here it says Chrome so they give us the actually Chrome browser that we’re using and the version, Mac OS and also there request language is English. Again, you could possibly use this to customize the different pages you want to send back to the user based on their browser type, OS type or their language type. Good job, an example of using that built-In Request Object.

Let’s go ahead and wrap up this video, in this video I’ll show you how to use some of the Built-in Server Objects. We may use the request object to find out the user’s operating system and browser. In the following videos we’ll do a drill down into some of the other objects and you can come and see them working out real world for various use cases.

Share