|
@@ -21,7 +21,8 @@ The power of the `Filter` comes from the `FilterChain` that is passed into it.
|
|
|
|
|
|
.`FilterChain` Usage Example
|
|
.`FilterChain` Usage Example
|
|
====
|
|
====
|
|
-[source,java]
|
|
|
|
|
|
+.Java
|
|
|
|
+[source,java,role="primary"]
|
|
----
|
|
----
|
|
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) {
|
|
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) {
|
|
// do something before the rest of the application
|
|
// do something before the rest of the application
|
|
@@ -29,6 +30,16 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha
|
|
// do something after the rest of the application
|
|
// do something after the rest of the application
|
|
}
|
|
}
|
|
----
|
|
----
|
|
|
|
+
|
|
|
|
+.Kotlin
|
|
|
|
+[source,kotlin,role="secondary"]
|
|
|
|
+----
|
|
|
|
+fun doFilter(request: ServletRequest, response: ServletResponse, chain: FilterChain) {
|
|
|
|
+ // do something before the rest of the application
|
|
|
|
+ chain.doFilter(request, response) // invoke the rest of the application
|
|
|
|
+ // do something after the rest of the application
|
|
|
|
+}
|
|
|
|
+----
|
|
====
|
|
====
|
|
|
|
|
|
Since a `Filter` only impacts downstream ``Filter``s and the `Servlet`, the order each `Filter` is invoked is extremely important.
|
|
Since a `Filter` only impacts downstream ``Filter``s and the `Servlet`, the order each `Filter` is invoked is extremely important.
|