How to include one JSP in another JSP Example





Hey guys in this article, you will learn about how to include JSP page in another JSP with easy to understand example

Read More:

Overview


To include JSP in another JSP file, we will use <jsp:include /> tag. It has a attribute page which contains name of the JSP file.

To include .html file

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

To include .jsp file

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

Complete Example


Follow the below steps to understand the complete example

Create a Project


You can check the following post to create a new Dynamic Web Project

Create a JSP file for Header


Create JSPHeader.jsp file under WebContent and add the following content

<div>
	<p>This is header</p>
</div>

Create a HTML file for Footer


Create footer.html file under WebContent and add the following content

<div>
	<p>This is footer</p>
</div>

Create a JSP file for Landing page


Create JSPTest.jsp file under WebContent and add the following content

<%@page import="in.bushansirgur.Test"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

	<jsp:include page="JSPHeader.jsp" />
	<p>Main content</p>
	<jsp:include page="footer.html" />
	
</body>
</html>

Run the file


Right click on the File, choose Run As, choose Run on Server. It will open in a default web browser, you will see the following content

1

That’s it for this post, if you like this post, please share this post with your friends and collogues and also share this on your social media profiles.



Bushan Sirgur

Hey guys, I am Bushan Sirgur from Banglore, India. Currently, I am working as an Associate project in an IT company.

Leave a Reply