jQuery in Action, 3rd edition
The moose likes Servlets and the fly likes filter response Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "filter response" Watch "filter response" New topic

filter response

alexander zevenbergen

Joined: Jun 27, 2006
Posts: 1
hi all

i need to rewrite an inputstream as an outputstream and send it out with the response in my filter. Can any body help me with this?

this is what i have and i'm not sure where i'm going wrong

What i'm trying to do is send a resource to a html page that requested it(in most cases a picture but can also be a style sheet)

Am i right in assuming that the wrapper stops the response and the printwriter sends my bytearray instead?

or did i miss some logic somewhere?

ramprasad madathil
Ranch Hand

Joined: Jan 24, 2005
Posts: 489

If you wanted the Filter to write back the response, you shouldnt have the doFilter() call on the FilterChain. doFilter() would invoke the next entity in the chain (which may be another Filter or a Servlet or a Jsp)

Having said that, I would recommend that you take a step back and have a careful look at your design. Filter blocking requests are a rarity. And in most cases, it would be conditional - an example would be to check for a certain attribute in session or the session itself (this can be done easily enough in the Controller too). Filters generally augment request and response handling (eg zipping up the response, adding a request parameter etc).

And finally the purpose of a ResponseWrapper is to prevent the Servlets or Jsp from writing to the response directly. Instead the Filter wraps the response object adding it's own custom OutputStream and then passes the request along. Now a Servlet or a Jsp would write to the Filter's output stream and when the Filter receives the response on its way back, it can extract the contents, make necessary changes (say zip it up) and then send the output to the browser.

Does that help?

I agree. Here's the link: http://aspose.com/file-tools
subject: filter response
It's not a secret anymore!