I understand how jsp:include and include directive work differently. I wonder what is the real difference.
include directive happens at translation time and jsp:include happens at run-time. Consider the following.
Say, I have A.jsp includes B.jsp using jsp:include. When a request comes in for A.jsp, the container creates and instantiates servlets for both A.jsp and B.jsp. Then, response from A.jsp is combined with response from B.jsp.
Now I change B.jsp, the only guaranteed way by SPEC is to redploy B.jsp. So I redeploy B.jsp. After that, jsp:include is guranteed to reflect the change but include directive may not (unless I have a container that detects it)
Is this right?
I would further say, if I have A.jsp and B.jsp in the same web app, there is no difference in jsp:include and include directive, because when I redeploy B, I am redploying the web app, which includes A.jsp.
I guess there is a bit more overhead using the include directive because of the fact that the Container has to include the whole of the page in the enclosing page and that may make the enclosing page huge.
On the other hand, using the jsp:include will probably be faster since the response is the only thing that is included.
The rule is that use include directive when you want to include stuff that rarely changes in a web app and use jsp:include for dynamic values.
include directve include directive can be used incude static file in a jsp file
jsp:include A servelet can trasfer a request to another resource to manage the response by using RequestDispatcher . The jsp has the same funtionality . Insted of acquiring handle to dispatcher the jsp:include tag is used temporaraly transfer control and allow the other resource to use request and response object. This tag enables you to incude static or dynamic content. if it is a static content ,it is included in the jsp page . if it is dynamic content ,request is send to the resource and returned content with the result is included in the jsp page
i think now you can get the clear idea of diffrence between these two
posted 15 years ago
Thanks Siva and others for clarifying.
I guess the most efficient way of including other jsp files is through jsp:include when the pages change quite often.