• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Filter and Struts

 
Wilson Gordon
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

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?

Thanks.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35276
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wilson,
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.
 
Wilson Gordon
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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);
response.sendRedirect("http://www.google.com");

Anyone know how I could resolve the problem?

Thanks.
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does your web.xml entry look like?

- Brent
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic