JSP directives || Include Directive in JSP

Include Directive in JSP

Include Directive in JSP is used to display the data of the page to another page. Let’s try to understand this concept by a real-time example.

For example, I need to develop a web application using JSP. and there are 20 pages in my application so in every page I need some common thing like header, footer, and sidebar something. So I have two choices I can create header and footer for every page. but it’s not a good programming practice. Now I have two follow another option which is the include directive. now I can create one header file and one footer file and Include this file on every page by using include directive.

Syntax for Include Directive

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

Example of Include Directive in JSP

header.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
  <h1>HEADER</h1>
</body>
</html>

footer.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<h1>FOOTER</h1>

</body>
</html>

home.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<%@ include file="header.jsp"%>
</head>
<body>
  <h3>Welcome to Codebun.com</h3>
</body>

<%@ include file="footer.jsp"%>
</html>

Taglib Directive in JSP

taglib directive in JSP is used to create the custom tag on JSP page. We’ll  discuss taglib in the custom tag upcoming tutorial.

Syntax of the taglib directive in JSP.

<%@taglib uri ="taglibURI" prefix="tag prefix"%>

 

Jsp directive || Page directive in JSP

 

One Comment

Add a Comment

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

sixteen + 7 =