Hello peeps, Could anyone tell me if it is possible to call the include() method (of RequestDispatcher) from inside a JSP, please? I have found it useful in the past, but cannot seem to get it to work properly at the moment. Only include() from a servlet appears to work, rather than throw an (unhelpful) exception. My main aim is to have a piece of Java being executed within a JSP which decides at that time which JSP should be included. I understand this (or something similar) is possible with the jsp:forward tag, but with jsp:include? Thanks for any help, Matt.
Bear Bibeault
Author and opinionated walrus
Marshal
That's exactly what <jsp:include> does. But there's no reason that you should not be able to call the include method within a scriptlet (but why do that when the tag exists to do it for you?) What part of using <jsp:include> is giving you problems? hth, bear [ January 18, 2003: Message edited by: Bear Bibeault ]
Ah, yes, I have just caught on - sorry. Quite nifty. Unfortunately, I'm not entirely sure it does what I'm looking for exactly. But then, I'm picky. Thanks, Matt.
David Hibbs
Ranch Hand
Joined: Dec 19, 2002
Posts: 374
posted
0
Originally posted by Matthew Webster: Ah, yes, I have just caught on - sorry. Quite nifty. Unfortunately, I'm not entirely sure it does what I'm looking for exactly. But then, I'm picky.
jsp:include should work fine. You can dynamically change the page included in your code by doing something like this in a scriptlet:
and specifying the include page as a rtexpr: <jsp:include page="<%=forwardPage%>" flush="true" />
"Write beautiful code; then profile that beautiful code and make little bits of it uglier but faster." --The JavaPerformanceTuning.com team, Newsletter 039.
Matthew Webster
Ranch Hand
Joined: May 10, 2001
Posts: 51
posted
0
Thanx for the help. I asked because in the past I have used pieces of Java to simply include other JSP's, sometimes in large and complex numbers. This function appeared to disappear when I tried a direct .include() in a JSP under the recent version of Tomcat. The evidence of this was that the output of the JSP being included appeared before any of the output from the JSP calling the include method. I am now happy as to an up-to-date methodology, but does anyone have an answer as to why the above happened?
Best regards, Matt.
boyet silverio
Ranch Hand
Joined: Aug 28, 2002
Posts: 173
posted
0
it may be that the include action was executed (with the result shown at the output) before the contents of the buffer which existed beforehand had been flushed out. the 'flush="true"' indicated by David in his sample <jsp include.../> put things in the right order. hope this helps.