StrutsPrepareAndExecuteFilter init方法,为什么会调用回调函数 postInit?postinit还是空函数,有什么用?

StrutsPrepareAndExecuteFilter init方法,为什么会调用回调函数 postInit?postinit还是空函数,有什么用?

如果你直接使用StrutsPrepareAndExecuteFilter的话,这个方法没有用。
但是,如果你继承StrutsPrepareAndExecuteFilter类,自定义一个过滤器的话,可以在你自己的类中override这个方法,然后在你自己的postInit方法里面写入你自己的代码。这样运行的时候,就会回调你自己写的postInit方法了。

比如:

class MyPrepareAndExecuteFilter extends StrutsPrepareAndExecuteFilter{

protected void postInit(Dispatcher dispatcher, FilterConfig filterConfig) {
System.out.println("call back source code");
}
}

然后在web.xml中把MyPrepareAndExecuteFilter配置到filter中。

filter初始化的时候,就会输出call back source code

楼上正解。
基本上就是给后面再次开发的人留个接口的意思。