What is the difference between <%jsp:include> and <%@include>?

<jsp:include> is standard action element but <%@include%> is the directive. Both appears to have the same job to insert the response of a file to a jsp page.
<%@include file=”header.jsp”%>
<jsp:include page=”header.jsp”/>
The <%@include%> includes the complete header.jsp into this page. But <jsp:include> includes the response of header.jsp into the jsp page. That means the include directive is compiledwith the other data in the generated servlet code. But the include action is some type of runtime call.
The include directive happens at translation time but include action happens at runtime.
The key to <jep:include> is that the container is creating RequestDispatcher from the page attribute and applying the include method.
Suppose the header.jsp only prints “hi bhabani” and included in Test.jsp
Then the generated servlet will look like,
FOR DIRECTIVE:
Out.write(<html><body>hi bhabani</body></html>);
………………………..
Other stuff of Test.jsp………….
FOR ACTION:
Org.apache.runtime.JspRuntimeLibrary.include(request,response,”header.jsp”,out,false);
……………….
Other stuff of Test.jsp………….
Note: in case of <jsp:include> little bit performance decrease because each time(runtime) it has to see the included file.
NOTE: Do not put opening and closing html and body tagswithen your reuseable pieces.

No comments:

Post a Comment