protected void doGet(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {// 判斷cookie是否有登錄信息Cookie[] cookies = req.getCookies();boolean isLogin = false;for(Cookie c : cookies){if("loginInfo".equals(c.getName())){String v = c.getValue();if(v!=null && !v.equals("")){isLogin = true;}}}// 有,登錄通過// 沒有,登錄驗證,設置登錄信息,設置cookie有效時間if(isLogin){System.out.println("用戶已登錄");}else{System.out.println("用戶未登錄");System.out.println("用戶信息驗證通過");Cookie c = new Cookie("loginInfo", "loginInfo");c.setMaxAge(Integer.parseInt(login_keep+""));resp.addCookie(c);}}
?