过滤器(filter)是一种类实现了javax.servlet.filte接口
写filter步骤:
创建类implement是javax.servlet,filter
实现方法:
@Override
public void destroy() {
}
@Override
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain arg2) throws IOException, ServletException {
System.out.println("efbbet");
}
@Override
public void init(FilterConfig arg0) throws ServletException {
}
在web,xml中配置filter
<filter>
<filter-name>TestFilter</filter-name>
<filter-class>com.zhfly.web.filter.TestFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>TestFilter</filter-name>
<url-pattern>/LoginServlet</url-pattern>
</filter-mapping>
监听器(listener)类可根据不同的需求实现了不同的Listener接口
步骤
创建类implement实现接口
实现方法:
@Override
public void sessionCreated(HttpSessionEvent se) {
// TODO Auto-generated method stub
}
@Override
public void sessionDestroyed(HttpSessionEvent se) {
// TODO Auto-generated method stub
}
在web,xml中配置listener
<listener><listener-class>com.zhfly.web.listener.TestListener</listener-class></listener>