This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Struts and the fly likes Struts2 Filter and Includes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts2 Filter and Includes" Watch "Struts2 Filter and Includes" New topic
Author

Struts2 Filter and Includes

J J Wright
Ranch Hand

Joined: Jul 02, 2008
Posts: 254
Hi,

I need to invoke a Struts2 action using <jsp:include> (I can't use <:s:action> because it doesn't result in a new request, and I need to be able to cache the response from the included action using a Servlet filter.). However, when I set up my Struts filter to handle includes



I get the following exception in Glassfish V2.1. Any suggestions?



SCJP, SCWCD, SCBCD, SCEA 5
J J Wright
Ranch Hand

Joined: Jul 02, 2008
Posts: 254
This doesn't work in Tomcat 6 either so I guess its a limitation / problem with Struts 2.1.6. I have to day I find it incredible you can't perform a JSP include on a Struts action.

I have a suspicion it will work when I use org.apache.struts2.dispatcher.ng.servlet.StrutsServlet as opposed to org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter. However, the API docs contain the following warning for using StrutsServlet:

This servlet dispatcher is only for those that really know what they are doing as it may not support every feature of Struts, particularly static resource serving.


All in all pretty disappointing - I may end up ditching Struts2 altogether.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I have no issues using <jsp:include> to include an action.
Your server wrote:
javax.servlet.ServletException: PWC1232: Exceeded maximum depth for nested request dispatches: 20

That error message leads me to believe it's either a recursive include, or you're doing something else funky, but that's just an off-the-cuff guess.
J J Wright
Ranch Hand

Joined: Jul 02, 2008
Posts: 254
Thanks for the reply,

How is your Struts filter set up? By default it won't process includes - did you have you add <dispatcher>INCLUDE</dispatcher>?




David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Yep; I used the configuration you showed in the first message.
J J Wright
Ranch Hand

Joined: Jul 02, 2008
Posts: 254
David,

I've attached the offending code for a very basic test. I'm assuming I must be doing something glaringly obvious wrong, but I can't see it.



Thanks very much for your help.

Jonathan

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

What happens if you use "date.action" as the page? (Or "/date.action"?)
J J Wright
Ranch Hand

Joined: Jul 02, 2008
Posts: 254
I still get the same error.
J J Wright
Ranch Hand

Joined: Jul 02, 2008
Posts: 254
I'll try it with an earlier release and see what happens
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

I'm running 2.1.6.
J J Wright
Ranch Hand

Joined: Jul 02, 2008
Posts: 254
I just tried the same example with 2.0.14 and everything worked as expected.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts2 Filter and Includes