Hey guys in this article, you will learn about how to include JSP page in another JSP with easy to understand example
Read More:
- Check the Complete JSP Tutorials
- Check the Complete Spring Boot Tutorials [100+ Examples]
- Check the Complete Spring Boot and Thymeleaf Tutorial
- Check the Complete AWS Tutorial
- Check the Complete JavaServer Faces (JSF) Tutorial
- Check the Complete Spring Data JPA Tutorial
- Check the Complete Spring Security Tutorial
- Check the Javascript Projects for Beginners
- Check the Spring Boot JdbcTemplate Tutorials
Table of Contents
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
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.