• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

diff. between jsp:include and include directive

 
Yan Zhou
Ranch Hand
Posts: 137
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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.

Does that sound right?
Thanks.

Yan
 
srinath anand
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both of your observations are correct.

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.
 
shiva viswanathan
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Srinath

I disagree with the statement that jsp:include is faster

In case of include directive initially the work is more since an entire file has to be included within another file.After that the work is much faster

However in case of jsp:include a run time dynamic call is made to the included jsp , each time since the response of the included jsp is to be added to the response of the enclosing jsp .

Hence include directive will always be faster that jsp:include . Hence the rule that only if jsp content changes frequently should you use jsp:include


Of course this hardly matters in case of an "intelligent" container

Catch You Later
Shiva
 
AmitKumar Jain
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to add the following points to your discussion..

1) <jsp:include cannot be used of files other than jsp like .html files. solution is to rename .html to .jsp.

2) while using @include, developer needs to be careful about naming conflict in variables in the two files. i.e there must not be the variable with the same name as the one in included file.
 
Narendra Dhande
Ranch Hand
Posts: 951
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Your quote
1) <jsp:include cannot be used of files other than jsp like .html files. solution is to rename .html to .jsp.


I don't think that the static html file should rename as .jsp. We can include .html files using <jsp:include> action.

Thanks
 
shiva viswanathan
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Narendra ,

No that is not true .

You can just rename a html file with a jsp extension and it will work fine.

A jsp file is simply a html file which can contain java
The presence of java is optional

Hope you get it

Catch You Later
Shiva
 
AmitKumar Jain
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for wrong info..

Narendra..you're right.. we can include .html/.txt files also with jsp include action.
Thanks for correcting me...
 
niroshan iranga
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
srinath anand
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic