Difference Between Static Include And Dynamic Include

Difference Between Static Include And Dynamic Include Example explains what are the Differences Between Static Include And Dynamic Include In JSP with example

You can also see an examples of jsp:forward and jsp:include examples below

1) JSP Forward Example

2) JSP Include Example

Static Include Example

<%@include> the contents of each file will be included at compilation phase. Static includes are much faster than dynamic includes.

include.jsp

<html>
<head>
<title>JSP Static Include Example</title>
</head>

<body>
    The current date and time are
    <%@ include file="date.jsp"%>
</body>

</html>

date.jsp

<%@ page import="java.util.*" %>
<%= (new java.util.Date() ).toLocaleString() %>
Output
Static Include Example

Dynamic Include Example

The "jsp:include"  tag includes the response or output of the pages dynamically. By using jsp:include tag, the included files are processed separately and included with final response only at runtime.

that's why it is also called as jsp dynamic include.

include.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>jsp:include example</title>
</head>
<body>
    This is a page<br/>
    <jsp:include page="welcome.jsp" />
</body>
</html>

welcome.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Welcome</title>
</head>
<body>
    Welcome Dynamic Include Is Working Now
</body>
</html>
Output
Dynamic Include Example










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