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 閱讀(1393) 評論(1)  編輯  收藏

          評論

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


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


          網站導航:
           
          主站蜘蛛池模板: 东明县| 桑日县| 广水市| 永州市| 长葛市| 手游| 河池市| 都昌县| 阿克陶县| 白朗县| 商河县| 竹山县| 昆明市| 重庆市| 宜兰县| 白朗县| 峨眉山市| 马公市| 清镇市| 五河县| 和顺县| 读书| 成都市| 潜山县| 米脂县| 临邑县| 开远市| 云霄县| 紫阳县| 固阳县| 宜州市| 巴马| 沁源县| 博爱县| 久治县| 临西县| 黑河市| 东乌珠穆沁旗| 称多县| 泸水县| 芒康县|