It's not a secret anymore!
The moose likes Struts and the fly likes Servlet Filters with struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Servlet Filters with struts" Watch "Servlet Filters with struts" New topic

Servlet Filters with struts

Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1082

Hi everyone

Have any one used Compression filter in struts.

I am facing little proplem in implementing it.

For compression filter read the article at

Two Servlet Filters Every Web Application Should Have

I have implemeted these filter in my struts based application .every thing is running fine with compress jpg .gif but when I add "*.do" to compress it gives me problem.

can any one tell me If we can add *.jsp in compression It gives no problem however it gives me problem for *.do .


Gravitation cannot be held responsible for people falling in love ~ Albert Einstein
Sheldon Fernandes
Ranch Hand

Joined: Aug 18, 2004
Posts: 157
When using Struts, all requests are sent to the Controller Servlet which then executes an Action and finally forwards to a view (I have taken this simple case as an example).

A filter is configured to process the request/response sent to the controller, using <url-pattern> or <servlet-name>. When the controller servlet forwards the request/response to the jsp (view), then the filter (if it is a post-processing filter) tries to write content to the reponse which is currently being used by the jsp (view) to which the forward was made. This causes an Exception to be thrown.

The Servlet 2.3 specification does not state how filters should behave when FORWARDS or INCLUDES are performed using a RequestDispatcher. The 2.4 version of the specification covers this in SRV.6.2.5 Filters and the RequestDispatcher.

Hope this answers your question.

Sheldon Fernandes
Shailesh Chandra
Ranch Hand

Joined: Aug 13, 2004
Posts: 1082

Dear Sheldon

Thanks for your valuable input.

but there is no exception at server end in my application every thing works fine when I use my gzip compresson filter.

but when I add *.do to compress I receive an error at IE browser that it tries to download the url.

Sean Owen

Joined: Nov 08, 2004
Posts: 21
I posted a similar note to another thread on this subject:

I think that GZipFilter will not work if the app server applies it twice to the same request, which can happen in 2.3 if there are any server-side forwards.

If I may be so bold as to plug my own work, I have created an open-source compression filter that is faster, cleaner and more comprehensive than GZipFilter. If the above is in fact your problem, you should give my filter a try; it works regardless of how the app server behaves in this situation.

PJL Compressing Filter
I agree. Here's the link:
subject: Servlet Filters with struts
It's not a secret anymore!