web.xml 使用舊配置:
<filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter>
啟動報警告:
*********************************************************************** * WARNING!!! * * >>> FilterDispatcher <<< is deprecated! Please use the new filters! * * This can be a source of unpredictable problems! * * https://struts.apache.org/2.x/docs/webxml.html * ***********************************************************************
FilterDispatcher 自 Struts 2.1.3 起標記 @Deprecated,官方建議替換為 StrutsPrepareAndExecuteFilter(或組合 StrutsPrepareFilter + StrutsExecuteFilter 需配合 ActionContextCleanUp)。
修改 web.xml:
<filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter>
重啟項目,警告消失,功能正常。
ng.filter 包下為新一代過濾器實現ActionContext,可配置兩個 Filter:StrutsPrepareFilter (pre) + StrutsExecuteFilter (post)web.xml 是必做項