• Post Reply Bookmark Topic Watch Topic
  • New Topic

including a struts action in my jsp page  RSS feed

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • 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
 
Ron Ditch
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why not build a jsp that builds a table, and include it inside of another jsp?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!