FilterDispatcher is deprecated! - What is the replacement for FilterDispatcher?

前端 未结 3 582
孤城傲影
孤城傲影 2021-01-01 19:22

How to avoid the following error? I am implementing Spring-Security on Struts2, the application runs perfectly but the following message will be shown on server log.

相关标签:
3条回答
  • 2021-01-01 19:53

    Since Struts 2.1.3, an addition method call is used in doFilter () method of FilterDispatcher to display the warning message.

    showDeprecatedWarning() prints the message on the console. It just a System.out.println().

     public void doFilter(....){
      showDeprecatedWarning();
        ........
     }
    
     private void showDeprecatedWarning() {
        String msg =
                "\n\n" +
                "***********************************************************************\n" +
                "*                               WARNING!!!                            *\n" +
                "*                                                                     *\n" +
                "* >>> FilterDispatcher <<< is deprecated! Please use the new filters! *\n" +
                "*                                                                     *\n" +
                "*           This can be a source of unpredictable problems!           *\n" +
                "*                                                                     *\n" +
                "*              Please refer to the docs for more details!             *\n" +
                "*            http://struts.apache.org/2.x/docs/webxml.html            *\n" +
                "*                                                                     *\n" +
                "***********************************************************************\n\n";
        System.out.println(msg);
    }
    

    But Struts2 recommends to use org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter instead of org.apache.struts2.dispatcher.FilterDispatcher.

    web.xml configuration

    <filter>
         <filter-name>struts2</filter-name>
         <filter-class>
             org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
         </filter-class>
    </filter>
    
    0 讨论(0)
  • 2021-01-01 19:55

    I'd recommend following the link and doing what it says:

    <filter>
        <filter-name>struts2</filter-name>
    
        <filter-class>
            org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
        </filter-class>
    </filter>
    
    0 讨论(0)
  • 2021-01-01 20:16

    The FilterDispatcher (org.apache.struts2.dispatcher.FilterDispatcher) is used in the early Struts2 development, and it’s deprecated since Struts 2.1.3.

    If you are using Struts version >= 2.1.3, it’s always recommended to upgrade the new filter class – StrutsPrepareAndExecuteFilter (org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter).

    for references

    FilterDispatcher documentation

    StrutsPrepareAndExecuteFilter documentation

    0 讨论(0)
提交回复
热议问题