JSP STANDARD ACTION jsp:include

                                      <jsp:include>
Introduction:
1.    The <jsp:include> element allows you to include either a static or dynamic file in a JSP file.
2.     If the file is static, its content is included in the calling JSP file. If the file is dynamic, it acts on a request and sends back a result that is included in the JSP page.
3.     When the include action is finished, the JSP container continues processing the remainder of the JSP file.
4.     If the included file is dynamic, you can use a <jsp:param> clause to pass the name and value of a parameter to the dynamic file.

Syntax:
<jsp:include   page= “header.jsp”  flush= “true”  />

The Response of header.jsp will be placed in the current response at request processing time (Run time).  Hence it is dynamic include.<jsp: include> is a tag representation of pageContext.include (“header.jsp”).This standard action contains the following 2 attributes.

§  page : It represents the name of the included page.  It is a mandatory attribute.

§  flush : It specifies whether the response will be flushed before inclusion (or) not. it is optional attribute. The default value is false.
      
< jsp:include page= “header.jsp” flush= “true”  />
 <%
 pageContext. include (“header.jsp”);
 %>

Example: first.jsp
    
     <h2>This is First JSP</h2>
     <jsp:include   page = "/second.jsp" %>



second.jsp
  <h2> This is second JSP  </h2>

Output:


Note : In total the following are 4 possible ways to perform inclusion.

§  Include Directive
<%@ include file= “header.jsp” %>
§  Include Action
<jsp:include page= “header.jsp” %>
§  By using pageContext implicit object
<%     pageContext.include(“header.jsp”);  %>
§   By using RequestDispatcher
<%
 RequestDispatcher  rd= request.getRequestDispatcher (“header.jsp”);
   rd.include(request, response);
%>
Thanks For Making This Possible! Kindly Bookmark and Share it.

Technorati Digg This Stumble Stumble Facebook Twitter

No comments:

Post a Comment