Topic: 关于过滤器

  Print this page

1.关于过滤器 Copy to clipboard
Posted by: white_clouds
Posted on: 2004-12-08 17:42

比如说我在web.xml中配置了过滤如下
<filter>
<filter-name>ContentTypeFilter</filter-name>
<filter-class>dlog4j.ContentTypeFilter</filter-class>
<init-param>
<param-name>contentType</param-name>
<param-value>text/xml;charset=UTF-8</param-value>
</init-param>
</filter>
在ContentTypeFilte程序中
String ct = config.getInitParameter("contentType");
在程序中是怎么得到这个参数的,是怎么实现的呢

2.Re:关于过滤器 [Re: white_clouds] Copy to clipboard
Posted by: bluepure
Posted on: 2004-12-08 18:47


package dlog4j;

public class ContentTypeFilter extends HttpServlet implements Filter {
private FilterConfig filterConfig;
private String ct=null;
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
//在这里得到
ct= filterConfig.getInitParameter("contentType");
}

//Process the request/response pair
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain filterChain) {
try {
//在这里进行处理

filterChain.doFilter(request, response);
} catch (ServletException sx) {
filterConfig.getServletContext().log(sx.getMessage());
} catch (IOException iox) {
filterConfig.getServletContext().log(iox.getMessage());
}
}

//Clean up resources
public void destroy() {
ct=null;
filterConfig=null;
}
}


3.Re:关于过滤器 [Re: white_clouds] Copy to clipboard
Posted by: white_clouds
Posted on: 2004-12-09 09:32

我是说filterConfig.getInitParameter("contentType")它是怎么取到的,它是怎么知道contentType的值,调用的过程是什么样的流程

4.Re:关于过滤器 [Re: white_clouds] Copy to clipboard
Posted by: bluepure
Posted on: 2004-12-09 10:05

去看tomcat的源码吧。


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923