最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

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

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

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

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

 <!--session過(guò)期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類(lèi)中,在init中讀取exclusions,并在doFilter中判斷。如下:

 public void doFilter(ServletRequest request, ServletResponse response, 
      FilterChain chain) throws IOException, ServletException { 
    // 由于 session 屬于 HTTP 范疇,故需要向下轉(zhuǎn)型成 HttpServletRequest 類(lèi)型 
    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{
             //原來(lái)的處理代碼
    }

  } 

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

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

相關(guān)文章

最新評(píng)論

边坝县| 庆安县| 宜州市| 太康县| 清远市| 大理市| 高安市| 保亭| 岢岚县| 四川省| 遂溪县| 贵阳市| 天全县| 金阳县| 安龙县| 阿拉尔市| 平度市| 南丰县| 新巴尔虎左旗| 交城县| 宁强县| 鹤山市| 福州市| 邯郸市| 绥德县| 潍坊市| 偏关县| 南岸区| 长治市| 巴中市| 油尖旺区| 祥云县| 铜山县| 孝感市| 鄂托克前旗| 承德县| 泗水县| 永德县| 新泰市| 莒南县| 伊通|