Jsp Include Directive

Jsp Include Directive

The JSP include directive <%@ include %> is used to merging external files (jsp file, html file or text file) into the current JSP page at translation time. The jsp page is translated only once so it will be better to include static resource or files.

Advantage of Include directive

Code Reusability

Syntax of include directive

<%@ include file="URL of the resource" %>

Example of include directive

In this example, we are including the content of the file1.jsp file into index.jsp file.

  1. index.jsp
    <html>
    <head>
    <title>Main JSP Page</title>
    </head>
    <body>
    <%@ include file="file1.jsp" %>
    Main JSP Page: The jsp page is translated only once so it will be better to include static resource or files.
    </body>
    </html>
  2. file1.jsp
    <p>
    This is my File1.jsp and I will include it in index.jsp using include directive
    </p>
    
    

     

Leave a comment