FilterDispatcher has been marked as deprecated workaround >>> FilterDispatcher <<< is deprecated!…

Some struts 2 tutorials are relatively early . When we implement code based on newer versions of struts2 , there are often problems . For example, this warning: FilterDispatcher isdeprecated!


The configuration in web.xml is as follows :

 

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

But it will appear as soon as it runs, as shown in the warning: FilterDispatcher is out of date! Please use the new filter!


Open the link mentioned in the warning, we can find the FilterDispatcher Example (web.xml)

<web-app id="WebApp_9" version="2.4" 
	xmlns="http://java.sun.com/xml/ns/j2ee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
        <init-param>
        	<param-name>actionPackages</param-name>
        	<param-value>com.mycompany.myapp.actions</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <!-- ... -->

</web-app>

This FilterDispatcher Example does not have a FilterDispatcher, but becomes this sentence:

org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter


Looking down, it turns out that from the version >= 2.1.3, FilterDispatcher is marked as obsolete and replaced by new

StrutsPrepareAndExecuteFilter


So if your struts version is greater than 2.1.3, the filter configuration should become:

org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter。

If it is lower than version 2.1.3, you can also use the configuration at the beginning of this article.

Reprinted in: https://www.cnblogs.com/Codenewbie/p/3642048.html

Related Posts