This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes doubts realted to include directive Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "doubts realted to include directive" Watch "doubts realted to include directive" New topic
Author

doubts realted to include directive

Dash Abhisek
Ranch Hand

Joined: Jul 20, 2008
Posts: 63
Hi All,


I read in a site that if the content of included page is not changing frequently then it is a better idea to use include directive and if it is changing then we should use include action.
my doubt is :- for a jsp to get displayed it is first compiled (just for once)
and for every change in the source code of the jsp it is again compiled now I am not getting if the jsp has to be compiled if changed then irrespective of
what we choose (include action or directive) it should take the same time in both cases and one approach should not be better than other.

Second thing I read is :- if you want your changes to be displayed instantly without deploying include action is the way to go for it .why?

One more doubt that I have is :-if content of your included jsp is not changing then using include directive saves overhead.why? is this because
the control doesn't need to go anywhere because the codes are pasted in the
parent jsp or for any other reason?

hope my understanding is correct. if anything is wrong please help me correct that

Thanks in advance...
Abhisek
Steve Luke
Bartender

Joined: Jan 28, 2003
Posts: 4167
    
  21

Originally posted by Dash Abhisek:
Hi All,


I read in a site that if the content of included page is not changing frequently then it is a better idea to use include directive and if it is changing then we should use include action.
my doubt is :- for a jsp to get displayed it is first compiled (just for once)
and for every change in the source code of the jsp it is again compiled now I am not getting if the jsp has to be compiled if changed then irrespective of
what we choose (include action or directive) it should take the same time in both cases and one approach should not be better than other.



In the jsp:include action, the included JSP is called, is if by a method call, whereas the include directive copies the content of the included JSP into the parent JSP. With the include directive, if you change the content of the included JSP then it needs to re-compile, but so too does the parent JSP doing the including. With a jsp:include this is not the case, so if the included page needs to be re-compiled then you do not need to re-compile the parent JSP as well.

This is such a minor concern that you shouldn't consider it when making a choice between the jsp:include action and the include directive. The real difference is dynamic interaction or not. The jsp:include is used for dynamic inclusion of material - if you want to include the JSP based on some parameters at run time, or if you need to pass parameters into the included JSP using parameters. Since the jsp:include occurs at runtime it can respond and act on runtime information.

The include directive is a static include, it occurs at compile time, so it can not include different files based on runtime information, or read URL parameters set at runtime. On the other hand, since it occurs when the parent JSP is first compiled there is no overhead for including the JSP each time the page gets requested by a user - which may make it a bit faster.


Originally posted by Dash Abhisek:
Second thing I read is :- if you want your changes to be displayed instantly without deploying include action is the way to go for it .why?


I hope the above answered this.

Originally posted by Dash Abhisek:
One more doubt that I have is :-if content of your included jsp is not changing then using include directive saves overhead.why? is this because
the control doesn't need to go anywhere because the codes are pasted in the
parent jsp or for any other reason?


Yes. With a jsp:include action there is a new method call, there is a possible modification to the Request Object, and some other setup-code needed to make sure that the page gets initialized properly to run. With the include directive there is no-such initialization because the code is copied right into the parent JSP.


Steve
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60782
    
  65

I'll reiterate something that Steve pointed out for emphasis: performance considerations between the two mechanisms are so slight as to be completely moot. Choose the one that makes the most sense, not the one that you think might be marginally faster.

Also, in JSP 2.0, tag files are a nice alternative to parameterized dynamic includes.
[ October 12, 2008: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Dash Abhisek
Ranch Hand

Joined: Jul 20, 2008
Posts: 63
Thanks for the valuable insights.My doubt is cleared
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doubts realted to include directive
 
Similar Threads
Sharing a scripting variable across JSPs
SkipPageException - Doubt
Problem in Include File
Having doubt in EL
doubt is session