Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why is ServletFilter.doFilter() not getting invoked?

 
Alex Ryan
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone have any idea why Tomcat (5.5.17) does not invoking the doFilter() method on my ServletFilter?
It seems to be invoking the init and destroy methods okay, but never doFilter().
I'll bet I'm doing something dumb.
Please advise.

public class PersistentSessionFilter implements Filter {

public PersistentSessionFilter() {
super();
}

public void init(FilterConfig arg0) throws ServletException {
System.out.println("PersistentSessionFilter.init()");
}

public void destroy() {
System.out.println("PersistentSessionFilter.destroy()");
}

public void doFilter(ServletRequest request, ServletResponse response, FilterChain arg2) throws IOException, ServletException {
System.out.println("PersistentSessionFilter.doFilter()");
}

}
 
krishna bala
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
please post your web.xml aso .
 
Alex Ryan
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>
quotations</display-name>
<filter>
<description>
</description>
<display-name>
PersistentSessionFilter</display-name>
<filter-name>PersistentSessionFilter</filter-name>
<filter-class>net.visualocity.filters.PersistentSessionFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>PersistentSessionFilter</filter-name>
<url-pattern>/PersistentSessionFilter</url-pattern>
</filter-mapping>
<servlet>
<description>
</description>
<display-name>
AddQuoteServlet</display-name>
<servlet-name>AddQuoteServlet</servlet-name>
<servlet-class>
net.visualocity.servlets.AddQuoteServlet</servlet-class>
</servlet>
...
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
 
shivendra tripathi
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To invoke doFilter you have to make sure the url you are submitting should have pattern like "/PersistentSessionFilter". Post your code/way you are trying to invoke the filter.
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you invoking a resource with '/PersistentSessionFilter' ? I doubt it .
 
krishna bala
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
your code is fine , i have tested it . for me it is calling doFilter . check log correctly
 
Alex Ryan
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops!
That was it.

The web.xml should've looked like this...

<filter-mapping>
<filter-name>PersistentSessionFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>

Thank you!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic