This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 30138

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
jQuery in Action, 2nd edition
subject: Filter and Struts
Similar Threads
Filter Problems in Web.xml
Struts2 struck with a issue of 404
Struts Filter in Web.xml
Struts Filter
using filters with struts