What is the purpose of javax.servlet.FilterChain?

I inherited a Struts 1 app that uses FilterChain heavily and I don't understand the benefits of this extremely confusing code.

"In a servlet API, you usually use a servlet when you want to control, preprocess, and / or post-process specific requests. But if you want to filter / modify general requests and / or responses based on certain conditions, then a filter is much more appropriate."

Every request in my app is based on certain conditions, such as a merchant ID or a search term. But it looks like placing a request in a whole chain of things that completely obscures what's coming from the developer trying to trace the cause of the error is nuts.

+3


source to share


2 answers


A colleague of mine (who hasn't signed up on SO) explained that he will apply global functionality to an application that you don't want to do in every single controller, like checking if a user is logged in.



+5


source


The call FilterChain#doFilter()

simply continues the HTTP request to the destination, proceeding exactly as if you weren't using the filter in the first place. This is usually a servlet class or even a JSP file. Thus, to debug the problematic code, it is better to place the breakpoint in the target code rather than in the filter if it does not contain the code of interest.



+5


source







All Articles