• Post Reply Bookmark Topic Watch Topic
  • New Topic

The second filter don't work?

 
Sam Wang
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
web.xml:
...
<filter>
<filter-name>WordFilter</filter-name>
<display-name>WordFilter</display-name>
<filter-class>stub.web.filter.WordFilter</filter-class>
</filter>
<filter>
<filter-name>counterfilter</filter-name>
<display-name>counterfilter</display-name>
<filter-class>stub.web.filter.CounterFilter</filter-class>
<init-param>
<param-name>FILE_NAME</param-name>
<param-value>counter.txt</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>WordFilter</filter-name>
<url-pattern>/controllerservlet</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>counterfilter</filter-name>
<url-pattern>/controllerservlet</url-pattern>
</filter-mapping>
...
Here is the doFilter of the second counterfilter:
public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) {
try {
InputStream in = filterConfig.getServletContext().getResourceAsStream(fileName);
p = new Properties();
p.load(in);
counter = Integer.parseInt(p.getProperty("counter"));
System.out.println("counter = "+counter);
p.setProperty("counter",String.valueOf(++counter));
p.store(new FileOutputStream(fileName),"");
filterChain.doFilter(request, response);
}catch(Exception e){
filterConfig.getServletContext().log(e.getMessage());
}
}
One more thing nly the doFilter of the second filter don't work,the others(like init and destory)work.
My env is tomcat4.0
[ May 09, 2002: Message edited by: Stub Wang ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!