不推荐使用FilterDispatcher! - FilterDispatcher的替代品是什么?

时间:2013-04-25 23:48:32

标签: struts2

如何避免以下错误?我正在Struts2上实现Spring-Security,应用程序运行完美,但以下消息将显示在服务器日志中。

 WARNING!!!                            
 FilterDispatcher <<< is deprecated! Please use the new filters!                                                                      
      This can be a source of unpredictable problems!                                                                  
         Please refer to the docs for more details!                           
         http://struts.apache.org/2.x/docs/webxml.html            

3 个答案:

答案 0 :(得分:36)

我建议按照链接进行操作:

<filter>
    <filter-name>struts2</filter-name>

    <filter-class>
        org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
    </filter-class>
</filter>

答案 1 :(得分:0)

FilterDispatcher(org.apache.struts2.dispatcher.FilterDispatcher)用于早期的Struts2开发,自Struts 2.1.3开始就被弃用。

如果您使用Struts版本&gt; = 2.1.3,则始终建议升级新的过滤器类 - StrutsPrepareAndExecuteFilter(org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter)。

供参考

FilterDispatcher documentation

StrutsPrepareAndExecuteFilter documentation

答案 2 :(得分:0)

自Struts 2.1.3起,在FilterDispatcher的doFilter ()方法中使用了一个加法方法调用来显示警告信息。

showDeprecatedWarning()在控制台上打印消息。它只是一个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);
}

但Struts2建议使用org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter代替org.apache.struts2.dispatcher.FilterDispatcher

web.xml配置

<filter>
     <filter-name>struts2</filter-name>
     <filter-class>
         org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
     </filter-class>
</filter>