• Post Reply Bookmark Topic Watch Topic
  • New Topic

Filter init?

 
Andrew Mcmurray
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all ,

I have a filter that I only want to be invoked if a user is not using IE. Is there a way in the init method to keep the doFilter method from being called if the user is using IE? Right now I put the logic in the doFilter method of the filter, but I wasn't sure if it was the best place to put it?

Thanks,

AMD
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65529
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You really have to do it on a request-by-request basis. You can't just do something like throw an UnavailableException because that will remove the filter from service for the entire app.
 
Andrew Mcmurray
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bear,

So it is acceptable to just have an if (UserAgent ...) statement in the doFilter method that does the check?

Thanks,

AMD
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65529
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure, and it's really the only way you can do it. You can't do anything in init because that's called once before anyone even hits the site.

If you want to minimize the processing, you could analyze the User-Agent string once and store the result in the session.
 
Andrew Mcmurray
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cool thanks!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!