• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

including a struts action in my jsp page

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey ho !
I have a Struts action (showTable.do) which displays a table.
I'd like to include this in several jsp pages.
Using the include action
<jsp:include page="/showTable.do?reg=1&by=reg" />
causes the following exception:
java.lang.IllegalStateException: Cannot forward after response has been committed
My workaround is the following:
<bean:include id="table" page="/showTable.do?reg=1&by=reg" />
<bean:write name="table" filter="false" />
and it works (hence the name, *work*around, hehe)
Is this the "real" way to do it ? I'm just not happy with my solution because it looks "rong"
thank you girlz'n'guyz
Dennis
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why not build a jsp that builds a table, and include it inside of another jsp?
 
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
The initial problem of course is that you are trying to fit a square peg in a round hole. A Struts action isn't intended for inclusion in a JSP page, it is intended to be a front controller for a view in a Model 2 web architecture. As such, at the end of the action the Struts engine forwards to whatever "action forward" target was returned by the execute/perform method of the action. And as we know, once output has been comitted to the response, forwards are disallowed. Hence your error.
Because of the forward at the end of the action, Struts actions aren't suitable for inclusion. If you are trying to reuse the logic of the action, a better approach would be to factor out the common logic so that both the action and your page can share it without the Struts action mechanisn getting in the way.
hth,
bear
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks ! I really like both of your answers.
Ron, this works fine and does exactly what I wanted it to do. Again, it feels strange to have a jsp page (the one I include) that only contains a forward to an action.
Bear, thanks for your hint; I will change my design so I don't "abuse" actions for sth they weren't made for. Still, the action (showTable.do) prepares the table that is 2b included and there4, I somewhat want to encapsulate the action which loads the data for the table and the page that displays it.
having an action for this, which I can include as well, seemed easy but I will rethink my strategy
twists'n'shouts
dennis
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic