Forums Register Login

JSP Include

+Pie Number of slices to send: Send
Hello friends,
There are two ways to 'include' a page in jSP, i.e:
a) <%@ include file="top.jsp" %>
b) <jsp:include page="top.jsp" flush="true" />
Can someone guide me the actual difference between the two.(I understand it is to do with the Scripting variables).
I would really appreciate an answer with some example .
Thanks,
Milan
+Pie Number of slices to send: Send
The short answer is that the first is the JSP tag, the second is the XML form.
From my experience their behaviour is implementation dependent.
For example in an earlier version of WebLogic App server (4.51 I think) one version of the tags created separate class files for each included jsp then concatenated the results, while the other tag created a single class file made up of all of the included elements.
When WebLogic 5.0 came out the behaviour was changed so that it only created a single class file.
Hope this helps in some way.
[This message has been edited by David O'Meara (edited March 20, 2001).]
+Pie Number of slices to send: Send
Thanks David for yourreply,
I would further appreciate if you can guide me about the consequence of this.
Morever I understand that there is something like static include (i.e <%@ include..> ) and dynamic include (i.e <jsp:include..> )
Can u tell me what exactly is it?
Regards,
MILAN
+Pie Number of slices to send: Send
If the included page will be changing (i.e. a table of contents), use jsp:include. This way, it includes the file at the time the jsp file is requested. You can use regular jsp scripting in the included file.
If the included file will not be changing much (i.e. a graphical header), use <%@ include file="foo" %>. It includes the file at the time the servlet is created. You can use regular jsp scripting in the included file here too.
Here's two links for you to read more:
http://www.apl.jhu.edu/~hall/java/Servlet-Tutorial/Servlet-Tutorial-JSP.html#Section8.1
http://www.jspinsider.com/reference/jsp/jspincludes.html
+Pie Number of slices to send: Send
If you want to talk 'gotchas' or pitfalls or comparisons etc...
Static includes all get compiled into a single class file. One downside of this is that if different parts declare the same methods or variables etc they cause errors that are not easy to detect. It can also promote 'bad' programming (my opinion) by treating variables aross several files as globals.
Dynamic includes have the overhead of sending a separate HTTP call when each part is required. One day I'll set up a demo and try to work out what that overhead is. The separate parts (should) all use the same request and response objects and can therefore use these to communicate.
Personally we've always used the static version where possible to reduce the overhead mentioned. If anyone has any actual values for the 'overhead' I'd be interested to see them. (They'd be implementation specific of course)
Barry's not gonna like this. Barry's not gonna like this one bit. What is Barry's deal with tiny ads?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1080 times.
Similar Threads
jsp include action: j2ee certificate.com question
@include v/s jsp:include
How to include a part of html code in to a jsp page?
who can explain the item to me?
what is flush attribute in jsp
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 03:50:41.