Rising Sun

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            148 隨筆 :: 0 文章 :: 22 評論 :: 0 Trackbacks
          public class SignonFilter implements Filter
          {
          String LOGIN_PAGE="login.jsp";
          protected FilterConfig filterConfig;

          //過濾處理的方法
          public void doFilter(final ServletRequest req,final ServletResponse res,FilterChain chain)throws IOException,ServletException
          {
          HttpServletRequest hreq = (HttpServletRequest)req;
          HttpServletResponse hres = (HttpServletResponse)res;
          HttpSession session = hreq.getSession();
          String isLogin="";
          try
          {
          isLogin=(String)session.getAttribute("isLogin");
          System.out.print(isLogin);
          if(isLogin!=null&&isLogin.equals("true"))
          {
          System.out.println("在SignonFilter中驗證通過");
          //驗證成功,繼續處理
          chain.doFilter(req,res);
          }
          else
          {
          //驗證不成功,讓用戶登錄。
          hres.sendRedirect("login.jsp");
          System.out.println("被SignonFilter攔截一個未認證的請求");
          }

          }
          catch(Exception e)
          {
          e.printStackTrace();
          }

          }

          public void setFilterConfig(final FilterConfig filterConfig)
          {
          this.filterConfig=filterConfig;
          }

          //銷毀過濾器
          public void destroy()
          {
          this.filterConfig=null;
          }
          /**
          *初始化過濾器,和一般的Servlet一樣,它也可以獲得初始參數。
          */
          public void init(FilterConfig config) throws ServletException {
          this.filterConfig = config;
          }

          }


          posted on 2006-07-27 15:19 brock 閱讀(1394) 評論(1)  編輯  收藏

          評論

          # re: 關于filter驗證用戶權限 2016-03-15 13:50 12
          333  回復  更多評論
            


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


          網站導航:
           
          主站蜘蛛池模板: 信阳市| 塔河县| 田阳县| 蓬莱市| 日照市| 张家港市| 临江市| 尼木县| 汾阳市| 赤壁市| 麻栗坡县| 革吉县| 抚州市| 溧阳市| 济宁市| 余庆县| 昆明市| 淮阳县| 常熟市| 威宁| 峨眉山市| 治县。| 双城市| 台北市| 双桥区| 阳城县| 高淳县| 四川省| 东至县| 和平县| 阿拉善盟| 泸定县| 五原县| 洪江市| 玛曲县| 原平市| 阿城市| 和顺县| 长子县| 嘉义市| 民勤县|