include action tag का इस्तेमाल current JSP page पर external file को include करने के लिए किया जाता है | ये external file HTML, JSP या Servlet हो सकती है |
JSP include directive ये page translation के दौरान file को page पर include करता है लेकिन include action tag; processing phase के request के दौरान JSP Page पर include होता है |
Syntax for include Action tag without Parameter in JSP
<jsp:include page="external_file" flush="bool" />
Syntax for include Action tag with Parameter(<jsp:param>) in JSP
<jsp:include page="external_file" flush="bool"> <jsp:param name="parameter_name" value="parameter_value"/> </jsp:include>
Attribute for include Action tag
page : यहाँ पर external file का नाम उसके extension के साथ दिया जाता है | अगर file दूसरे location पर होती है तो उसका path भी दिया जा सकता है |
flush : Optional. यहाँ पर flush के लिए true या false ये boolean value दी जाती है | अगर true दिया जाता है तो include होने से पहले include होनेवाली file का buffer flush किया जाता है और अगर दिया नहीं जाता या false दिया जाता है तो buffer flush नहीं किया जाता है |
Example for include Action tag without parameter in JSP
Example पर sample.jsp इस file पर myhtmlfile.html इस file को include किया गया है |
External File : myhtmlfile.html<html> <body> <h2>Hello World</h2> </body> </html>
sample.jsp
Output :<html> <body> <h1>Header</h1> <jsp:include page="myhtmlfile.html" flush="true" /> <h1>Footer</h1> </body> </html>
Header
Hello World
Footer
Example for include Action tag with Parameter(<jsp:param>) in JSP
Example पर include action के साथ param action को लिया गया है | यहाँ पर sample इस file द्वारा myname इस paramater को myfile इस file पर pass किया गया है |
myfile.jsp<%= request.getParameter("myname") %>
sample.jsp
Output :<html> <body> <h1>Header</h1> <jsp:include page="myfile.jsp" flush="true"> <jsp:param name="myname" value="UD" /> </jsp:include> <h1>Footer</h1> </body> </html>