On 12/12/05, David Evans <[EMAIL PROTECTED]> wrote:
> Hello all,
>
> I have a requirement for a dynamically created menu on all pages of a
> web site i am creating. So i created an action that creates a List of
> MenuItems, and then forwards to a jsp that uses jstl to forEach through
> the list and generate the appropriate html. the jsp page only has the
> snippet of html for the menu div of the page. I am including this action
> in "static" html pages via the use of apaches SSI module like this:
> <!--#include virtual="/apps/footer" -->
>
> and thought i was going to use jsp:include to include it in all of the
> jsp pages to which my applications actions are forwarding, like this:
> <jsp:include page="/apps/footer" />
>
> However when i attempt to do that i get a:
>
> java.lang.IllegalStateException: Cannot forward after response has been
> committed
>
> This does work:
> <c:import url="http://www.domainname.com/apps/footer"; />
> but i'd prefer not to have to use that, because then i'll have to change
> it when things move from dev to production, so far my jsp's have no site
> specific information, so i can just copy them.
>
> So can someone tell me how/if i can include the results of an action in
> a jsp that is being forwarded to from another action?
>
> Thanks
>
> Dave

First of all, seems that you use older JSP container, which flushes
inclided fragments. I guess this is the cause of your error. You need
to use JSP 1.2+ to be able to not flush included fragments.

Even if you do use JSP 1.2+, you won't be able to forward from
included fragment because servlet spec sucks. Read more about it in my
article in the chapter "JSP/Servlet compatibility":
http://today.java.net/pub/a/today/2005/08/04/jspcomponents.html?page=3

So, I believe that you don't have luck with <jsp:include> before
servlet spec gets updated. I stuck at the same spot, and I built a
roundtrip.

Instead of this:
  composite page -> (include) -> Struts action -> (forward) -> JSP fragment
I use this:
  composite page -> (include) -> Struts action, returns null
                  -> (render) -> JSP fragment

So, no forwarding from included fragment now, all according to spec.
Check out http://jspcontrols.sourceforge.net for more insight. Also,
see live demos here: http://www.superinterface.com/jspcontrols

As a bonus, the component can be included via <jsp:include> and then
updated with Ajax. Ajax-enabled component works in non-Ajax browser
too.

Caveat: in this version the components are based on HTML FORM only.
Next version will allow to use any HTML fragment. But you can borrow
some ideas for yourself.

Michael.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to