• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSP Include

 
Milano Doshi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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).]
 
Milano Doshi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
liz munroe
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic