• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Calling include() within a JSP

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67754
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 374
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 173
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic