0

I used the following Java EE Filter for some pages:

    <filter-mapping>
        <filter-name>MyFilter</filter-name>
        <url-pattern>/index.jsp</url-pattern>
        <url-pattern>/user/*</url-pattern>
        <url-pattern>/article/*</url-pattern>
        <dispatcher>REQUEST</dispatcher>
        <dispatcher>FORWARD</dispatcher>
    </filter-mapping>

I deployed my project on a domain, like www.mydomain.com and I set as welcome page the file index.jsp.

If I visit www.mydomain.com, it shows the welcome page, but the filter doesn't work because it doesn't match with the rule.

If I visit www.mydomain.com/index.jsp , everything is working well.

So, all I want to do is the filter matches when I visit www.mydomain.com (because index.jspis being showed).

How could I do it?


Update: I tried the following pattern, but it didn't work:

<url-pattern>/</url-pattern>
Ommadawn
  • 2,450
  • 3
  • 24
  • 48
  • 1
    Not much experience here but if you go to "/" then your servlet is presumably forwarding to the /index.jsp page and by that time it has already gone through the filters. So, why not a "/" url pattern in your filters? – K.Nicholas Jun 23 '19 at 22:02
  • I tried that with no luck :( Thanks for your try – Ommadawn Jun 23 '19 at 22:11
  • 1
    @WebFilter("/*") public class ResponseFilter implements Filter { – K.Nicholas Jun 23 '19 at 22:15
  • @K.Nicholas the problem of that is that it will match with all the pages I use in my site (every one). – Ommadawn Jun 23 '19 at 22:24
  • 2
    true. I think if for some reason you want only to filter on the "/" url, and then some other url's but not others you will have to make the homepage an HTML 302 redirect to something like /home and filter on that. `` – K.Nicholas Jun 24 '19 at 01:49

0 Answers0