• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

WebFilter Annotation and servletNames attribute

 
Murat Balkan
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have a problem with a filter deployment. I have a very simple filter that just outputs a message to the console via a System.out.println call.
To test the filter, I created a simple Servlet named TestServlet which actually does nothing in its doGet. TestServlet has been deployed on servlet path /TestServlet under the webcontent (MyProject)
I confirm that I can call the servlet via http://localhost:8080/MyProject/TestServlet without any problems.

My problem is, when I specify the servlet name in WebFilter annotation, tomcat seems to ignore it. (ServletFilter is not triggered.)

@WebFilter(servletNames = { "TestServlet" })
public class TestFiltre implements Filter {}

But when I use urlPatterns attribute, The filter works fine.

@WebFilter(urlPatterns = { "/TestServlet" })


Does Tomcat support servletNames in Filters? Or I have a configuration problem?

Thanks a lot,

Murat
 
Vigneswaran Marimuthu
Greenhorn
Posts: 24
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Murat Balkan wrote:Does Tomcat support servletNames in Filters? Or I have a configuration problem?


i have used filters via eclipse and tomcat. Either you should give servletname or url-pattern in the filter-mapping of the web.xml file.

Ya Tomcat supports servlet names in filters. giving servlet names in filter-mapping is old practise and now they are using url-pattern. For me tomcat 6 supports both type. i need to check in tomcat 7. but surely it should work !!!
 
Murat Balkan
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I removed the annotation from the filter and added a web.xml file to the project. I made the necessary changes in web.xml:

<filter>
<filter-name>Filtre1</filter-name>
<filter-class>filtreler.Filtre1</filter-class>
</filter>
<filter-mapping>
<filter-name>Filtre1</filter-name>
<servlet-name>TestServlet</servlet-name>
</filter-mapping>

And it does not work again. TestServlet runs but filter is not triggered. I can see that the init method of the filter runs, so it is loaded by the container.

Right after that, I tried changing the above code with this:

<filter>
<filter-name>Filtre1</filter-name>
<filter-class>filtreler.Filtre1</filter-class>
</filter>
<filter-mapping>
<filter-name>Filtre1</filter-name>
<url-pattern>/TestServlet</url-pattern>
</filter-mapping>

And it works! So it is not about the annotations or web.xml file. It seems Tomcat ignores the <servlet-name> usage.

Any thoughts? Could this be a bug? Has someone test the same on Tomcat 7?

Thanks a lot,

Murat

 
Vigneswaran Marimuthu
Greenhorn
Posts: 24
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Today i ll confirm and will say you. I didnt check it in Tomcat 7
 
Vigneswaran Marimuthu
Greenhorn
Posts: 24
Eclipse IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am using eclipse indigo. For me web.xml is not visible. i dont know why. In the earlier versions of eclipse web.xml is visible. But i used servlet-name but tomcat responded with an infinite loop. Even for url-pattern too same response. I guess some mismatch in web.xml file. But i cant able to see it. I ll confirm and post you !!!
 
Alexander Sales
Ranch Hand
Posts: 89
Eclipse IDE Java Tomcat Server
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you don't have a servlet-name for your servlet?...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic