Two Laptop Bag*
The moose likes Servlets and the fly likes Why is ServletFilter.doFilter() not getting invoked? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Why is ServletFilter.doFilter() not getting invoked? " Watch "Why is ServletFilter.doFilter() not getting invoked? " New topic
Author

Why is ServletFilter.doFilter() not getting invoked?

Alex Ryan
Greenhorn

Joined: Aug 12, 2009
Posts: 14
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

Joined: Jul 20, 2009
Posts: 59
please post your web.xml aso .
Alex Ryan
Greenhorn

Joined: Aug 12, 2009
Posts: 14
<?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

Joined: Aug 26, 2008
Posts: 263
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.


SCJP 1.5(97%) My Blog
Sebastian Janisch
Ranch Hand

Joined: Feb 23, 2009
Posts: 1183
Are you invoking a resource with '/PersistentSessionFilter' ? I doubt it .


JDBCSupport - An easy to use, light-weight JDBC framework -
krishna bala
Ranch Hand

Joined: Jul 20, 2009
Posts: 59
your code is fine , i have tested it . for me it is calling doFilter . check log correctly
Alex Ryan
Greenhorn

Joined: Aug 12, 2009
Posts: 14
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why is ServletFilter.doFilter() not getting invoked?
 
Similar Threads
manipulate HttpServletResponse content in ServletFilter
When destroy method is called?
Help Needed in Filter Code
Tomcat 4.0 problem with Filter class
Filter life cycle