亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

http請(qǐng)求繞過Filter的實(shí)現(xiàn)實(shí)例

 更新時(shí)間:2017年06月19日 10:17:46   投稿:lqh  
這篇文章主要介紹了http請(qǐng)求繞過Filter的實(shí)現(xiàn)實(shí)例的相關(guān)資料,需要的朋友可以參考下

http請(qǐng)求繞過Filter的實(shí)現(xiàn)實(shí)例

場(chǎng)景:兩個(gè)web服務(wù)器,A當(dāng)做服務(wù)端,B為客戶端,B通過Hessian遠(yuǎn)程訪問A。A上加了session過期filter,通過用戶信息檢查session是否過期。這種情況下,Hessian會(huì)先發(fā)給filter,filter讀不到用戶信息就會(huì)認(rèn)為過期了,引起錯(cuò)誤。

解決方案:讓hessian請(qǐng)求繞過session過期filter。

filter配置中,不能加exclusion,所以需要用初始化參數(shù)給出不過濾的請(qǐng)求。本例中不過濾的格式為>/SarService。

 <!--session過期filter -->
 <filter>
 <init-param>
  <param-name>exclusions</param-name>
  <param-value>/SarService</param-value>
 </init-param>
 <filter-name>loginFilter</filter-name>
 <filter-class>org.sigsit.vinca.sar.filter.LoginFilter
 </filter-class>
 </filter>
 <filter-mapping>
 <filter-name>loginFilter</filter-name>
 <url-pattern>/*</url-pattern>
 </filter-mapping>

Filter類中,在init中讀取exclusions,并在doFilter中判斷。如下:

 public void doFilter(ServletRequest request, ServletResponse response, 
      FilterChain chain) throws IOException, ServletException { 
    // 由于 session 屬于 HTTP 范疇,故需要向下轉(zhuǎn)型成 HttpServletRequest 類型 
    HttpServletRequest req = (HttpServletRequest) request; 
    HttpServletResponse res=(HttpServletResponse)response;
     
    HttpSession session = req.getSession(); // 取得 session 
    
    String username = (String) session.getAttribute("username"); 
    StringBuffer fileURL = req.getRequestURL();

    if(fileURL.indexOf(this.exclusions)!=-1){
        chain.doFilter(request, response); 
    }
    else{
             //原來的處理代碼
    }

  } 

 public void init(FilterConfig config) throws ServletException {
 // TODO Auto-generated method stub
 this.exclusions=config.getInitParameter("exclusions");
 }

感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

相關(guān)文章

最新評(píng)論