File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Filter and Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Filter and Struts" Watch "Filter and Struts" New topic

Filter and Struts

Wilson Gordon
Ranch Hand

Joined: Apr 07, 2007
Posts: 89

I tried to add a filter to my application to filter requests, but it doesn't seem to intercept any request. Is there a problem with using filter and Struts together? How can I get it to work?

Jeanne Boyarsky
internet detective

Joined: May 26, 2003
Posts: 29249

No problem. I use filters and Struts. Have you tried a bare bones "Hello World" filter to see if it gets called? If so, I recommend posting your additions for the filter in the web.xml to the servlets forum to ask what is wrong.

[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Wilson Gordon
Ranch Hand

Joined: Apr 07, 2007
Posts: 89
Hi Jeane,

Thanks for the reply.

I added some logging and looks like the filter does get invoked.

What I try to achieve is to alter the response to add cookies from the session attributes. To do that, I created a wrapper class that implements the HttpResponseWrapper interface, and passed the wrapped response object into the chain filter. Below the chain filter call, I called addCookie method on the response object. The strange thing is the cookies don't seem to get added.

Any idea?
Wilson Gordon
Ranch Hand

Joined: Apr 07, 2007
Posts: 89
Here is my doFilter method code:

The cookie doesn't get set for some reason. Any idea?
[ October 31, 2007: Message edited by: Wilson Gordon ]
Wilson Gordon
Ranch Hand

Joined: Apr 07, 2007
Posts: 89
I also tried the following and it didn't redirect me to Google. Looks like I can't modify the response for some reason.

chain.doFilter(wrappedRequest, wrappedResponse);

Anyone know how I could resolve the problem?

Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
What does your web.xml entry look like?

- Brent
I agree. Here's the link:
subject: Filter and Struts
Similar Threads
using filters with struts
Struts Filter
Struts2 struck with a issue of 404
Struts Filter in Web.xml
Filter Problems in Web.xml