how to exclude a url in filtermapping

galao picture galao · Feb 14, 2013 · Viewed 32.9k times · Source

web.xml

<filter>
    <filter-name>SessionCheckFilter</filter-name>
    <filter-class>filter.SessionCheckFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>SessionCheckFilter</filter-name>
    <url-pattern>/faces/app/admin/*</url-pattern>
</filter-mapping>

I'm trying to exclude the /faces/app/admin/index.xhtml only, is there any way to do this?

If there's no exclude a url patterin in web.xml, maybe I can manipulate the doFilter() method to exclude the url?

Answer

Abhinay picture Abhinay · Jun 3, 2015
      public void doFilter(ServletRequest servletRequest,
                     ServletResponse servletResponse,
                     FilterChain filterChain) throws IOException,
                                                     ServletException {
        HttpServletRequest request=(HttpServletRequest)servletRequest;

           String path = request.getPathInfo();
          if ((path != null) && (!path.equals("your path")){
         // write filter logic
            }
     }

Try above code.