Fox Fox - 1 year ago 83
Java Question

Servlet web.xml filter -- Class not found exception

I am having a problem setting up the filter -
the filter I have defined in web.xml looks like this


But I am getting the following error -

SEVERE: Exception starting filter Log
java.lang.ClassNotFoundException: test.log
at org.apache.catalina.loader.WebappClassLoader.loadClass(
at org.apache.catalina.loader.WebappClassLoader.loadClass(
at org.apache.catalina.core.DefaultInstanceManager.loadClass(
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(
at org.apache.catalina.core.DefaultInstanceManager.newInstance(
at org.apache.catalina.core.ApplicationFilterConfig.getFilter(
at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(
at org.apache.catalina.core.ApplicationFilterConfig.<init>(
at org.apache.catalina.core.StandardContext.filterStart(
at org.apache.catalina.core.StandardContext.startInternal(
at org.apache.catalina.util.LifecycleBase.start(
at org.apache.catalina.core.ContainerBase$
at org.apache.catalina.core.ContainerBase$
at java.util.concurrent.FutureTask$Sync.innerRun(
at java.util.concurrent.ThreadPoolExecutor.runWorker(
at java.util.concurrent.ThreadPoolExecutor$

I have the class defined but for some reason I am getting the Classnotfoundexcetion. Can someone help me out?

EDIT ---

I have a package called test and a class called log.

package test;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;

// Implements Filter class
public class log implements Filter {
public void init(FilterConfig config) {

public void doFilter(ServletRequest request,
ServletResponse response,
FilterChain chain)
throws, ServletException {

// Get the IP address of client machine.
String ipAddress = request.getRemoteAddr();

// Log the IP address and current timestamp.
System.out.println("IP "+ ipAddress + ", Time "
+ new Date().toString());

// Pass request back down the filter chain
public void destroy( ){
/* Called before the Filter instance is removed
from service by the web container*/

Thank You,

Sid Sid
Answer Source

The filter-class parameter needs to be a Java class that should implement the Filter interface. Can you check if that's the case with you?

Check this example for guidance:

From the above link:

        <param-value>This parameter is for testing.</param-value>

public class LogFilter implements Filter {

    public void doFilter(ServletRequest req, ServletResponse res,
            FilterChain chain) throws IOException, ServletException {...