Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Filter using Request Dispatcher - using JavaEE 6 Annotations

I have created a filter for "/folder/*" using the JaveEE 6 Annotation

@WebFilter("/folder/*")

However when I go to "/test.html" which has a call

request.getRequestDispatcher("/folder/test.jsp").forward(request, response);

in the doGet, the page is not filtered. When going to "/folder/test.jsp" manually in the browser, the filter works fine. How can I make it work when using a dispatcher also?

I have found a solution for the xml way of creating filters multiple places such as here or here but have been unable to find a solution using annotations. Thanks!

like image 971
ET13 Avatar asked Jun 27 '26 13:06

ET13


1 Answers

The annotations seems to have a dispatcherTypes attribute to support this, so the following should work:

@WebFilter(value={"/folder/*"},
           dispatcherTypes={DispatcherType.REQUEST, DispatcherType.FORWARD})
like image 190
Jörn Horstmann Avatar answered Jun 30 '26 01:06

Jörn Horstmann



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!