Try the following:

- Put you filter into a package, I've seen some versions of the JVM that really don't like non-package classes.
- Make sure you are using settings compatible with the JVM that Tomcat is running under when compiling the class.


joelsherriff wrote:

I've done that, thanks.  Here's what I added for the filter:

   <filter>
       <filter-name>timerFilter</filter-name>
       <filter-class>TimerFilter</filter-class>
   </filter>

   <filter-mapping>
       <filter-name>timerFilter</filter-name>
       <url-pattern>/*</url-pattern>
   </filter-mapping>

to my web.xml.  It appears to be finding it properly.  If I change the
filter name to a non-existent filter, I
properly get a ClassNotFoundException.  So it's something IN the filter, or
so it would seem.  All I've
done is copy an example filter from the web - it looks like:

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class TimerFilter implements Filter {

 private FilterConfig config = null;

 public void init(FilterConfig config) throws ServletException {
   this.config = config;
 }

 public void destroy() {
   this.config = null;
 }

 public void doFilter(ServletRequest request, ServletResponse response,
                    FilterChain chain) throws IOException, ServletException
{
   long before = System.currentTimeMillis();
   chain.doFilter(request, response);
   long after = System.currentTimeMillis();

   String name = "";
   if (request instanceof HttpServletRequest) {
     name = ((HttpServletRequest)request).getRequestURI();
   }
   config.getServletContext().log(name + ": " + (after - before) + "ms");
 }
}




----- Original Message ----- From: "Anhony" <[EMAIL PROTECTED]>
To: "Tomcat Users List" <tomcat-user@jakarta.apache.org>
Sent: Thursday, April 28, 2005 9:48 AM
Subject: Re: How to use servlet filters without modifying webapp





Greetings,

Try adding a <filter> block to your web.xml. Your JSP container locates


your


filters thru these sections in the web.xml. I included a small sample
<filter> block below.

<filter>
    <filter-name>processingFilter</filter-name>
    <filter-class>servletFilters.ProcessingFilter</filter-class>
</filter>

I hope this helps.

Anthony-



----- Original Message ----- From: "joelsherriff" <[EMAIL PROTECTED]>
To: "Tomcat Users List" <tomcat-user@jakarta.apache.org>
Sent: Thursday, April 28, 2005 9:36 AM
Subject: How to use servlet filters without modifying webapp



Hello, I'm experimenting with applying a servlet filter to an existing webapp and I'm getting a ClassCastException upon startup. Can I do this without modifying the webapp source and adding my filter in there? If so, what else could be causing this?

I'm not sure where it looks for the filter .class file but I put it in the
webapp's WEB-INF/classes directory - I guess it finds it
since I'm getting this error.  The filter really does nothing, I'm just
trying to get A filter in place before making it more complicated.



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]







--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]




-- Robert r. Sanders Chief Technologist iPOV (334) 821-5412 www.ipov.net


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to