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.

<%@ include file="Header.jsp" %>

<jsp:include page="footer.jsp" />

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:

<%@ page language="java" contentType="text/html; charset=windows-1256" pageEncoding="windows-1256" %>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1256">
<title>Login Page</title> </head>
<body>
<%@ include file="Header.jsp" %>
<form name="actionForm" action="LoginServlet" method ="GET">
<table>
<tr><td>Enter your Username: </td><td><input type="text" name="uname"/></td></tr>
<tr><td>Enter your Password: </td><td><input type="password" name="password"/></td></tr>
<tr><td colspan="2" align="center"><input type="submit" value="submit"> </td></tr>
</table>
</form>
<jsp:include page="footer.jsp" />
</body>
</html>

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.

Related Posts

  • Abstract Class In JAVA

    Hello Friends, This tutorial is for all the Java followers. One of the best feature that is widely used is the term ‘Abstract’. This term can be used as either class or a simple method. An abstract method is any method that is just declared but not instantiated. In other words one can just create…

  • Threads in Java.

    Hello Friends, This is the tutorial for the java developers. One of the most significance feature of core java is Threading. Threading deals with the processing of Threads in a single java program. Let us learn what actually are Threads. *What are Threads? Threads are independently running processes that are isolated from each other upto…

  • Collections In Java.

    Hello friends, Welcome to another tutorial for java followers. You all may have heard about Collections, it is one of the amazing feature in java. Collections are the object for the group of elements, these elements are nothing but the different data structures like as Array Lists, Linked Lists, Vectors, Hash tables,Hash List, Trees, Hash…

  • Maven Installation.

    Hello Friends, This is one of my tutorial for installation of Maven on windows. Maven is a software project management tool. Based on the concept of a project object model (POM), Maven can manage a project’s build, reporting and documentation from a central piece of information. Maven is an open source community and is a…

  • Jira Plugin Deployment.

    Hello Friends, This is one of the most important tutorial for all the jira developers. You may have heard about the plugins in jira which is a simple Java Archive File with .jar extension. This JAR file contains the class files and auxiliary resources associated with the applications. In Jira we can use Eclipse IDE…

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.