JSP include directive

JSP include directive is used to merge or include the content of other resource into the current JSP page during translation phase. Other resource can be jsp, html or a text file. It provides the facility of code reusability.

Syntax: <%@ include file=”Relative URL” %>

Example:

welcome.jsp

<html>
	<head>
		<title>include directive example</title>
	</head>
	<body> 
		<h3>Hello this is an include directive example.</h3>
		<%@ include file="hello.jsp" %>  
	</body>
</html>

hello.jsp

<html>
	<head>
		<title>Hello</title>
	</head>
	<body>
		<h3>This content is of "hello.jsp" file.</h3>
	</body>
</html>

web.xml

<web-app>
 
  <welcome-file-list>
          <welcome-file>welcome.jsp</welcome-file>
  </welcome-file-list>	
 
</web-app>

Output:

jsp example 16
 
Download this example.
 
Next Topic: JSP taglib directive with example.
Previous Topic: info attribute in JSP page directive with example.

Related Topics:

import attribute of JSP page directive with example.
Session attribute of JSP page directive with example.
buffer attribute in JSP page directive with example.
autoFlush attribute in JSP page directive with example.
contentType attribute in JSP page directive with example.
isErrorPage and errorPage attribute in JSP page directive with example.
isThreadSafe attribute in JSP page directive with example.
language attribute in JSP page directive with example.
info attribute in JSP page directive with example.
JSP include directive with example.
JSP taglib directive with example.