Intercepting Filter设计模式,在Web曾处理前进行过滤。一种很有用的过滤是用户是否登陆的安全性检查。即在以下的doFilter函数中添加安全性检查的语句,这样就不需要对每个页面(servlet)进行安全性配置。
通常通过实现javax.servlet.Filter接口实现,其主要方法有:
| Method Summary | |
void | destroy() Called by the web container to indicate to a filter that it is being taken out of service. |
void | doFilter(ServletRequest request, ServletResponse response, FilterChain chain) The doFilter method of the Filter is called by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain. |
void | init(FilterConfig filterConfig) Called by the web container to indicate to a filter that it is being placed into service. |
然后在web.xml中配置过滤器即可。
本文介绍了InterceptingFilter设计模式的应用,该模式允许在Web请求处理前进行过滤操作,如用户登录验证等。通过实现`javax.servlet.Filter`接口并覆盖`doFilter`方法来完成过滤逻辑。此外,文章还提供了在`web.xml`中配置过滤器的方法。
608

被折叠的 条评论
为什么被折叠?



