doFilter called twice, intended behaviour?

后端 未结 8 1641
孤街浪徒
孤街浪徒 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 17:09

    Yes it is, Filter is executed twice in the life cycle, first calls when request from client come to servlet and second time when response is served to the client after execution of servlet.

    The order of execution is somehow looks like this.

    0 讨论(0)
  • 2021-02-19 17:15

    As @BalusC said, in my case the browser was requesting the favicon.ico by default, so there was an error in the browser's console

    Failed to load resource: the server responded with a status of 404 (Not Found)
    

    So I followed this answer and the error dissapeared but then I got the filter to get called twice.

    MY SOLUTION

    I replaced

    <link rel="shortcut icon" href="#" />
    

    For this:

    <link rel="shortcut icon" href="../assets/img/valid_icon.png" />
    
    0 讨论(0)
提交回复
热议问题