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  回復  更多評論
            


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


          網站導航:
           
          主站蜘蛛池模板: 平定县| 海伦市| 宜宾县| 新巴尔虎右旗| 石渠县| 嘉禾县| 麻栗坡县| 商水县| 镇雄县| 凤山市| 丰台区| 瓦房店市| 青川县| 上思县| 宁蒗| 南充市| 宜阳县| 洪泽县| 伊宁市| 中方县| 胶州市| 中超| 定结县| 铜鼓县| 静宁县| 韶关市| 丹阳市| 板桥市| 苍梧县| 漳浦县| 策勒县| 蒙阴县| 贡嘎县| 张家口市| 高雄县| 山东| 金平| 积石山| 深州市| 临海市| 东台市|