If I have a JSP page which carries out a database query and returns a drop-down box of all the returned results, should I <jsp:include> this or just <include> it? Obviously the returned HTML will be different every time. Does that hint at <jsp:include> ? Is <include> just for jsp pages that return the same HTML every time? Hope someone can help clear this up for me.
Filling a drop-down list with data dynamically SELECTED from a database doesn't imply the *need* to use an include of either type. Can you explain why you think you need one?
I use including to break pages into logical pieces and to reuse sections on multiple pages.
How do you choose between the two kinds of includes? One difference that everyone mentions is *when* the including happens. The jsp:include action is evaluated at request time, so if the included file has been editted, this is detected and it will be recompiled. On the other hand, the include directive <%@ include file="" %> is evaluated when the page containing the directive is compiled -- it's essentially a copy-and-paste operation, so that later changes to the included file may not be detected.
Either of these would work for the original poster if the fragment being included is jsp that loads data using select from his database. Don't confuse compiling with running this code! The code will always be run at request time.
All this being said, I use the jsp:include action almost exclusively, and not for the "editting the included file" reason. I think that the include directive leads to code bloat, if the fragment is pasted in multiple places. The include action has a small runtime overhead, but that is nothing to worry about.
Finally, there is one place where you have to always use the include directive. If you are putting all your taglib directives in a single file, you'll have to use the include directive to use that fragment:
Thanks for all your replies. I'm building a web site - much as Jeff described - and trying to keep it as modular as possible. So all the pages are actually lots of JSPs all <jsp:included> together. My understanding is something like this then ... if I <jsp:include> my DropDown.jsp, I can upload a new DropDown.jsp and it will be detected and incorporated. However, if I were to <include> it, an upload will not necessarily be detected and the changes might not be visible until the parent JSP is retranslated. If that's the case, and the overhead is minimal, I'll stick to <jsp:include>
As far as I know, In terms of performance, Standard include action would be better than directive include. Because executing a big JSP file in a single shot would take more time and memory. Am I right?
mak pandian wrote:As far as I know, In terms of performance, Standard include action would be better than directive include. Because executing a big JSP file in a single shot would take more time and memory. Am I right?
Probably not. But regardless, supposed performance and memory micro-optimization should not be use to determine which approach to take. Use whichever one makes the most sene, and is most suited to the task.