tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Robert r. Sanders" <robert.sand...@ipov.net>
Subject Re: How to use servlet filters without modifying webapp
Date Thu, 28 Apr 2005 14:26:10 GMT
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" <anthonys123@comcast.net>
>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" <joelsherriff@comcast.net>
>>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: tomcat-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>>
>>
>>    
>>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tomcat-user-help@jakarta.apache.org
>
>  
>

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


---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org


Mime
View raw message