Mark Estrada
Mark Estrada

Reputation: 9191

@WebFilter is not processed in my Glassfish

I have a filter in my code with below settings.. I mapped everything in the value request

@WebFilter(value="/*",  dispatcherTypes={DispatcherType.REQUEST, DispatcherType.FORWARD})
public class MyFilter implements Filter {
    public void init(FilterConfig fConfig) throws ServletException {
        logger.info("Inside init of MyFilter");
    }
}

My web.xml configuration is declared like this

<web-app 
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    version="3.0">

When deployed to Glassfish 3.1.2, I checked the server logs during startup but even my init method is not called. No errors or exception is being called also.

Anyone has idea how to troubleshoot?

Upvotes: 0

Views: 1271

Answers (1)

Oded Peer
Oded Peer

Reputation: 2427

According to the tutorial

Use the @WebFilter annotation to define a filter in a web application. This annotation is specified on a class and contains metadata about the filter being declared. The annotated filter must specify at least one URL pattern. This is done by using the urlPatterns or value attribute on the annotation. All other attributes are optional, with default settings. Use the value attribute when the only attribute on the annotation is the URL pattern; use the urlPatterns attribute when other attributes are also used.

As your annotation has more attributes you should use the "urlPatterns" attribute instead of "value"

Upvotes: 2

Related Questions