URL mapping in Tomcat to FrontController servlet

后端 未结 4 1802
太阳男子
太阳男子 2021-01-04 16:47

I\'m trying to follow the pattern at Design Patterns web based applications. It all works fine part from when it comes to maping \"root\" URLs.

I\'d like to put all

4条回答
  •  粉色の甜心
    2021-01-04 17:16

    Why do we need to map each and every URL. In case you need to map all the URL, you might need skip URL in the filter.

       
        SessionFilter
        SessionFilter
        com.colabcom.goshare.app.base.filter.SessionFilter
      
      
        sessionFilter
        /*
      
    

    In Your Filter,

            HttpServletRequest request = (HttpServletRequest) req;
            HttpServletResponse response = (HttpServletResponse) res;
            String url = request.getServletPath();
            boolean allowedRequest = Utility.filterURL(url, avoidUrls);
            if(allowedRequest){
                chain.doFilter(request, response);
            }else{
                //Main Filter Code           
            }
    

    Utility Class to filter your URL:

     public static boolean filterURL(String str, List avoidURLList) {
        boolean exist = false;
    
        if(avoidURLList == null){
            return exist;
        }
        for (int i = 0; i < avoidURLList.size(); i++) {
            if (str.contains(avoidURLList.get(i))) {
                exist = true;
                break;
            }
        }
        return exist;
    }
    

    Else you can map specific URL in your web.xml like

    
        sessionFilter
        *.action
      
    

提交回复
热议问题