You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Richard Mixon (qwest)" <rn...@custco.biz> on 2004/01/22 17:27:07 UTC

RE: Struts + Filter Chain = broken?

I just came across this thread and was hoping for a little more information :)

I understand what Craig is saying, then given the following situation:
 - a servlet 2.3 container (e.g. Tomcat 4.1.x);
 - a Struts app that returns ActionForward with redirect="false";

Then a servlet filter will not be able to manipulate the response generated by the ActionForward (which designates a JSP).

Is the above correct?

The reason I'm asking is I have a few pages that generate SVG graphics. In order to support better printing I was hoping to use a
filter to do an optional translation on the SVG response to a PDF format.

I will be moving to Tomcat 5 soon, but was hoping to implement the feature while we were still on Tomcat 4.1.x.

Thanks - Richard

-----Original Message-----
From: Craig R. McClanahan [mailto:craigmcc@apache.org]
Sent: Sunday, December 28, 2003 11:10 AM
To: Struts Users Mailing List; Oscar Picasso
Subject: Re: Struts + Filter Chain = broken?


Quoting Oscar Picasso <os...@yahoo.com>:

> I have a problem using filter chain with Struts
>
> I have wrote a simple filter to use in a servlet
> filter chain for postprocessing JSP output.
>
> It works like this:
>
> 1. Receive request, wrap response with its own
> response wrapper, and then pass it to filter chain.
>
> 2. The filter own response wrapper stores content in
> its own buffer when any call is made to
> response.getOutputStream().write().
>
> 3. When request returns from filter chain - get
> content from buffer, apply an xslt transformation &
> then flush the transformed content to the original
> response.getOutputStream().
>
> This all works fine when I request directly a JSP
> page.
>
> However if the JSP page is request by a struts
> forward, when the request returns from the filter
> chain - the original
> response.getOutputStream().write() never prints
> anything to the browser.
>

In a Servlet 2.3 environment (i.e. Tomcat 4.x), filters are only applied based
on the *original* request URI (the one that selects your Action), not on the
one use to forward to a JSP page.  In a Servlet 2.4 environment (i.e. Tomcat
5.x), you can also ask for the filter to be applied on request dispatcher
calls, but you have to make this explicit:

    <filter-mapping>
        <filter-name>MyFilter</filter-name>
        <url-pattern>myjsppage.jsp</url-pattern>
        <dispatcher>FORWARD</dispatcher>
    </filter-mapping>


> Any idea?

Craig McClanahan


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org


RE: Struts + Filter Chain = broken?

Posted by "Craig R. McClanahan" <cr...@apache.org>.
Quoting "Richard Mixon (qwest)" <rn...@custco.biz>:

> I just came across this thread and was hoping for a little more information
> :)
> 
> I understand what Craig is saying, then given the following situation:
>  - a servlet 2.3 container (e.g. Tomcat 4.1.x);
>  - a Struts app that returns ActionForward with redirect="false";
> 
> Then a servlet filter will not be able to manipulate the response generated
> by the ActionForward (which designates a JSP).
> 
> Is the above correct?
> 

Not quite.

Let's say you have an Acton mapped to "/getData.do" that forwards to
"/generateSVG.jsp" to create the SVG output.  Ideally, you'd like to map your
filter to the "/generateSVG.jsp" URL because that is the generator of the
output that is actually being filtered.  And you can do that in Servlet 2.4 if
you specify in the filter mapping that it applies to forwards.  But this is the
part that isn't supported in a Servlet 2.3 environment.

However, if you map your filter to "/getData.do" instead, it will work -- from
the perspective of the filter, it does not know or care how many forwards you
do inside the servlet to create the response, it just processes whatever
response is returned.

Craig


---------------------------------------------------------------------
To unsubscribe, e-mail: struts-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: struts-user-help@jakarta.apache.org