• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to redirect through filter chain

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an application and for every request it passes through a chain of filters. Depending upon certain condition I want the reesponse to break out of a filter and get forwarded to certain url how can I achieve this.

I have tried

dispatcher.forward(..)
response.sendDirect(..)

both does not work.

I even tried

response.flushBuffer()

but it does not break out of the filter chain and executes doChain() so effectively what happens that it executes the page where i want it to be redirected and goes back again to the location redirected by the filter.
 
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you break out of the filter chain by not calling filterchain.doFilter(). You will wind up in the resource that you originally requested (Servelt of JSP)
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

both does not work.



This is not a useful description of what is happening.

You should certainly be able to either forward or redirect from a filter.
 
Arun Kumar
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actully i can see the forward and redirect both working as i have put in the sop's in the script of the page but...........after that is done it starts executing the filter chain and which takes it to the other url which was originally invoked and for which the filter chain were working.

My intention is that the processing should stop after the forwarded/redirected page is served.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The forward and sendRedirect methods are no different than any other Java method call. They have no way of halting the execution of their calling method.

You will need to structure your code in such a way that either forward/sendRedirect OR doFilter is called.

 
Arun Kumar
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ben!!

This is helpful.........I was conceptually wrong........I thought that once the the redirction or forward is executed it will break out of filter chain on it's own.

I have now made the changes.


Appreciate your help.
 
reply
    Bookmark Topic Watch Topic
  • New Topic