Sets the filter’s {@link #setFilterConfig filterConfig} and then immediately calls {@link #onFilterConfigSet() onFilterConfigSet()} to trigger any processing a subclass might wish to perform.
设置过滤器的{@link #setFilterConfig filterConfig},然后立即调用{@link #onFilterConfigSet() onFilterConfigSet()}来触发子类可能希望执行的任何处理。
public final void init(FilterConfig filterConfig) throws ServletException {
setFilterConfig(filterConfig);
try {
onFilterConfigSet();
} catch (Exception e) {
if (e instanceof ServletException) {
throw (ServletException) e;
} else {
if (log.isErrorEnabled()) {
log.error("Unable to start Filter: [" + e.getMessage() + "].", e);
}
throw new ServletException(e);
}
}
}
onFilterConfigSet()
Template method to be overridden by subclasses to perform initialization logic at start-up.
模板方法,由子类重写,以在启动时执行初始化逻辑。
The
* {@code ServletContext} and {@code FilterConfig} will be accessible
* (and non-{@code null}) at the time this method is invoked via the
* {@link #getServletContext() getServletContext()} and {@link #getFilterConfig() getFilterConfig()}
* methods respectively.
当通过{@link #getServletContext() getServletContext()}和{@link #getFilterConfig() getFilterConfig()}方法调用此方法时,{@code ServletContext}和{@code FilterConfig}将是可访问的(和非{@code null})。
{@code init-param} values may be conveniently obtained via the {@link #getInitParam(String)} method.
{@code init-param}值可以通过{@link #getInitParam(String)}方法方便地获得。
protected void onFilterConfigSet() throws Exception {
}
总的来说,这个抽象类可以做的事情是:
1、设置FilterConfig,并且设置ServletContext
2、获取FilterConfig
3、获取init-param ?
4、做初始化 ?