Skip to Content
0
Apr 24, 2009 at 11:59 AM

Servlet Filter

21 Views

Hi,

I'm trying to use a servlet filter.

I created this class:

package com.test 

import java.io.IOException;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;

public class myFilter implements Filter{

	public void destroy() {
		System.err.println("DESTROY FILTER!!");
	}

	public void doFilter(
		ServletRequest request,
		ServletResponse response,
		FilterChain chain)
		throws IOException, ServletException {
		
                      System.err.println("DO FILTER!!");
		
	}

	public void init(FilterConfig filterConfig) throws ServletException {
		System.err.println("INIT FILTER!!");
	}

}

this is the web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
	<filter>
		<filter-name>myFilter</filter-name>
		<display-name>My filter</display-name>
		<filter-class>com.test.myFilter</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>myFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
</web-app>

When I deploy this filter, I can see the "DESTROY FILTER!!" en "INIT FILTER!!" in the logfile.

Then I clicked some links in the portal, but there is no "DO FILTER!!" int he logfile.

Can sombody help me?

thanks,

Joachim