doFilter called twice, intended behaviour?

后端 未结 8 1596
孤街浪徒
孤街浪徒 2021-02-19 16:42

I\'m working through the Java EE servlet tutorial and tried the mood example. I noticed the doFilter is getting called twice, once the servlet call is in the chain and the secon

8条回答
  •  感动是毒
    2021-02-19 16:54

    chain.doFilter(request,response);
    

    This will pass the control to the servlet the filter is associated with. But after the corresponding servlet is executed, the control comes back at the end of the above line and all the lines thereafter in the current doFilter() is executed.

    If you want to pass the control permanently to the servlet and not letting it return to the filter, just add a

    return;
    

    at the end of chain.doFilter(request,response) line in the current filter.

提交回复
热议问题