氟塑料離心泵www.buybeng.com

          jquery教程http://www.software8.co/wzjs/jquery/

          基于Spring JdbcTemplate 的分頁處理

          傳統(tǒng)的基于B/S的應(yīng)用中,Session會話超時后通常是跳轉(zhuǎn)到應(yīng)用的首頁,但Ajax請求的處理方式有些不同,下面簡單介紹一下Ajax請求的Session超時處理(超時后返回首頁)

          1.首先創(chuàng)建一個Filter

          1. import java.io.IOException;  
          2.   
          3. import javax.servlet.Filter;  
          4. import javax.servlet.FilterChain;  
          5. import javax.servlet.FilterConfig;  
          6. import javax.servlet.ServletException;  
          7. import javax.servlet.ServletRequest;  
          8. import javax.servlet.ServletResponse;  
          9. import javax.servlet.http.HttpServletRequest;  
          10. import javax.servlet.http.HttpServletResponse;  
          11.   
          12. public class AjaxSessionTimeoutFilter implements Filter {  
          13.   
          14.     public void destroy() {  
          15.   
          16.     }  
          17.   
          18.     public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {  
          19.         HttpServletRequest req = (HttpServletRequest) request;  
          20.         HttpServletResponse res = (HttpServletResponse) response;  
          21.         // 判斷session里是否有用戶信息  
          22.         if (req.getSession().getAttribute("SPRING_SECURITY_CONTEXT") == null){  
          23.             // 如果是ajax請求響應(yīng)頭會有,x-requested-with;  
          24.             if (req.getHeader("x-requested-with") != null && req.getHeader("x-requested-with").equalsIgnoreCase("XMLHttpRequest")){  
          25.                 res.setStatus(911);//表示session timeout  
          26.             }else{  
          27.                 chain.doFilter(req, res);  
          28.             }  
          29.         }else{  
          30.             chain.doFilter(req, res);  
          31.         }  
          32.     }  
          33.   
          34.     public void init(FilterConfig chain) throws ServletException {  
          35.   
          36.     }  
          37. }  

          2.在web.xml中增加以下配置

          1. <filter>  
          2.     <filter-name>ajaxSessionTimeout</filter-name>  
          3.     <filter-class>org.tshark.framework.web.filter.AjaxSessionTimeoutFilter</filter-class>  
          4. </filter>  
          5. <filter-mapping>  
          6.     <filter-name>ajaxSessionTimeout</filter-name>  
          7.     <url-pattern>/*</url-pattern>  
          8. </filter-mapping>  

          3.設(shè)置Ajax調(diào)用全局參數(shù)

          [javascript] view plaincopy
          1. $.ajaxSetup({  
          2.     contentType : "application/x-www-form-urlencoded;charset=utf-8",  
          3.     complete : function(xhr, textStatus) {  
          4.         $.ts.hideLoading();  
          5.         //session timeout  
          6.         if (xhr.status == 911) {  
          7.             window.location = rootPath + "/";//返回應(yīng)用首頁  
          8.             return;  
          9.         }  
          10.     }  
          11. });  

          posted on 2012-10-23 15:41 你爸是李剛 閱讀(1431) 評論(2)  編輯  收藏


          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導(dǎo)航:
           
          <2012年10月>
          30123456
          78910111213
          14151617181920
          21222324252627
          28293031123
          45678910

          導(dǎo)航

          統(tǒng)計(jì)

          常用鏈接

          留言簿

          隨筆檔案

          文章檔案

          技術(shù)網(wǎng)站

          行業(yè)網(wǎng)站

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          站長網(wǎng) 氟塑料離心泵 注塑機(jī) 液晶廣告機(jī)
          主站蜘蛛池模板: 唐河县| 阿拉尔市| 金沙县| 绿春县| 蓝田县| 松滋市| 贡山| 郸城县| 台南市| 敦化市| 咸阳市| 高阳县| 万载县| 商河县| 郓城县| 浦北县| 凌云县| 溆浦县| 永修县| 祁门县| 顺平县| 榆中县| 江陵县| 浦江县| 神木县| 云和县| 北川| 五莲县| 望都县| 黄梅县| 沙河市| 沙洋县| 山阳县| 潜山县| 眉山市| 咸阳市| 盘锦市| 洮南市| 齐河县| 济源市| 万宁市|