标签:
过滤器要做的事情:</filter-mapping>
/**************************************************************/
//过滤器必须实现Filter接口
public class BeerRequestFilter implements Filter{
private FilterConfig fc;
//完成清理工作
@Override
public void destroy() {
// TODO Auto-generated method stub
}
//具体的业务逻辑
@Override
public void doFilter(ServletRequest req, ServletResponse resp,
FilterChain chain) throws IOException, ServletException {
// TODO Auto-generated method stub
HttpServletRequest httpReq = (HttpServletRequest) req;//可以将请求和响应对象强制转换为Http类型
String name = httpReq.getRemoteUser();
if(name != null){
fc.getServletContext().log("User"+name +"is updating");
}
chain.doFilter(req, resp);//接下来要调用的过滤器或者servlet
}
//必须实现init 通常仅仅在其中保存配置config对象
@Override
public void init(FilterConfig config) throws ServletException {
// TODO Auto-generated method stub
this.fc = config;
}
}
/***************************************************************/
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/gaoanchen/article/details/47147717