Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Calling include() within a JSP  RSS feed

 
Matthew Webster
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Matthew Webster
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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" />
 
Matthew Webster
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 173
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!