JSP Include Directive

shape Description

JSP Include Directive – JSP include directive includes the other JSP file during the translation phase either static or dynamic of the including file. At the time of translation from JSP page to Servlet, the process includes “include” directive. This include directive is used for reusing information on several pages likes HTML and JSP. The include directive tag facilitates re-usability of code and the page translation time which translates only once. It is mainly used for static pages.
Syntax
<%@ page include file = “relative url” %>

The filename in the include directive is actually a relative URL. If the programmer just specify a filename with no associated path, the JSP compiler assumes that the file is in the same directory as your JSP. Following is the XML equivalent of the above syntax as follows.

<jsp:directive.include file="relative url" />

shape Example

Following is the simple example to understand the over all concept of JSP Include Directive.

indexinclude.jsp

<html>
		<head>
			<title>Main JSP Page</title>
		</head>
        <body>
            <%@ include file="file1.jsp" %>
 
 
             SPlessons underpins you bright coding knowledge.
                     
 
             <%@ include file="file2.jsp" %>
         </body>
</html>

Here the developer created file1.jsp and file2.jsp, those files have little message so while compile the code everything will be printed.
file1.jsp


		Splessons will provide you coding tutorials.

file2.jsp

"Do struggle and get results well then be like an example person""

Output

Output will be as follows, where include two files in main file.

Include directive and include action tag both are utilized for including a document to the current JSP page. However there is a distinction in the way they including document. Include directive includes the document at interpretation time, while the include action includes the record at run time. On the off chance that the included document is changed yet not the JSP which is including it then the progressions will reflect just when the developer utilize include action tag. The progressions won’t reflect on the off chance that you are utilizing include directive as the JSP is not changed so it won’t be interpreted for solicitation handling and subsequently the progressions won’t reflect.

Summary

shape Key Points

  • JSP Include Directive used to give less code.
  • The prime advantage with include tag is reusability.
  • Include tag and include directive tags are used to insert other pages.