ADS

Using @Include Directive In Jsp

The following example illustrates using @include directive in JSP.
       This directive is used to include a file (typically jsp or html) into a JSP page. Let us now see a simple example of how this works.


Syntax

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

As you can see, you are passing an attribute called file with takes the file to be embedded.

JSP file - index.jsp

 
<html>
    <body>
    This is in the html body

    <%
    out.println("This is in scriptlet");
    %>
   
    <%@include file="sample.html"%>
    </body>
</html>

sample.html

 
<html>
    <body>
    <h2>This is a h2 heading</h2>
    <p>This is a paragraph in sample.html</p>
    </body>
</html>

In this way you can also include as many files you want regardless of their file type as far as the web browser can show it to the user.

Subscribe to receive free email updates:

ADS