include action JSP Example jsp:include

include action JSP Example jsp:include

include action JSP Example

It is similar to include directive of syntax <%@ include file="somefile" %> . But they differ in how container treats or execute them. The differences we see later and let us first go into the code include action JSP Example.

In include action, at request time, the included JSP file is translated separately (apart including JSP file) to a Servlet source code file, compiled and output of execution is added to the output of including file and sent to client as response. Here, two separate Servlets are generated, compiled and executed. Only at the time output sending to client, they are merged. See the figure.

include action JSP Example

It is the difference with include directive where in include directive, only one Servlet is created and is explained with figure in JSP include directive with Example and Screenshots.

Example on include action JSP Example

1. Including page, File Name: SeparateState.jsp

2. Included page, File Name: Telangana.jsp

include action JSP Example

<jsp:include page="Telangana.jsp" flush=”true” />

The include action takes two attributes of page and flush.

1. page attribute takes relative path of included page, interpreted relative to the current JSP file. The include file can be static HTML file or dynamic JSP file.

2. flush is optional which takes a boolean value of true or false. If true, the response content is put into buffer before sent to client. Default is false.

Writing above include is known as include action. The difference between include directive and include is given at 11 Differences between JSP include directive and include action and is very important to know for the Programmer.

Leave a Reply

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