Jsp include file

Hello Friends,

This is one of the simple tutorials on jsp include file. Most of the time in any of the web application we need some part of the application on almost each of the pages. So, writing the code in each of the pages is really tedious and is not the best practice. For example, if we have a web application where we have to use the Header code and Footer code on every page then its the best practice to write the code once in a separate file and then import that file or its contents into the page where we want it to be displayed.

There are two ways to do this.

They both works same.  The <jsp:include> element allows you to include either a static or dynamic file in a JSP file. If the file is static, its content is included in the calling JSP file. If the file is dynamic, it acts on a request and sends back a result that is included in the JSP page. When the include action is finished, the JSP container continues processing the remainder of the JSP file.

This is the simple Example:

Here, header file is included using first option and footer file is included using second option. They both will work similar. Hope this small tutorial helps you. 🙂

Thanks,

Nikhil Naoghare.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.