wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Unable to get the filter to work Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Unable to get the filter to work" Watch "Unable to get the filter to work" New topic
Author

Unable to get the filter to work

Ann Basso
Ranch Hand

Joined: Jul 26, 2007
Posts: 48
Hi,
I have the following in my web.xml:

As I understand I am applying the filter on "default" servlet. This is what the specification says for it: "A string containing only the ’/’ character indicates the "default" servlet of the application. In this case the servlet path is the request URI minus the context path
and the path info is null."

When I access http://localhost:8080/mywebapp/, it shows the index.jsp page and I am also expecting this filter to execute but it is not. I don't understand why. When I chage the url pattern to /*, it does execute but not for /. I tried it on tomcat as well as glassfish.

How to I apply a filter to this default servlet?
thanks!
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1529
    
  22

Hi Ann,

You should be able to create a filter on the default servlet.

Can you post the part of your web.xml where you define the default servlet (<servlet> and <servlet-mapping>)?

Regards,
Frits
Ann Basso
Ranch Hand

Joined: Jul 26, 2007
Posts: 48
Frits Walraven wrote:Hi Ann,

You should be able to create a filter on the default servlet.

Can you post the part of your web.xml where you define the default servlet (<servlet> and <servlet-mapping>)?

Regards,
Frits

Hi Frits,
There is no definition for default servlet. That's why it is called the default servlet. When the app context is not able to match the incoming request uri to any of the url-mappings, the request is passed on to the default servlet. It generally looks for index.html/jsp or generates a 404 response. So if you call, http://localhost:8080/mywebapp/, it looks for index.jsp in document root. So I am trying to apply the filter to "/".

thanks!
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1529
    
  22

Hi Ann,

When the app context is not able to match the incoming request uri to any of the url-mappings, the request is passed on to the default servlet.

Correct, and that is the entry in the web.xml with an url-pattern of "/". So you are the one who has to define it.

It generally looks for index.html/jsp

What you describing here is the <welcome-file-list> entry in the web.xml

After you have defined the default servlet for your web-application, you can aply the filter to it:


Regards,
Frits
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unable to get the filter to work
 
Similar Threads
Filter Mapping
Confirmation Required(About Filter Sequence)
filter-mapping doubt??
order of filter mapping
Servlet Filter chain construction order