コード例 #1
0
 public static String getCookieValue(Cookie[] cookies, String cookieName, String defaultValue) {
   for (int i = 0; i < cookies.length; i++) {
     Cookie cookie = cookies[i];
     if (cookieName.equals(cookie.getName())) return (cookie.getValue());
   }
   return (defaultValue);
 }
コード例 #2
0
ファイル: CookieServlet.java プロジェクト: hiCarlosSilva/eap
 protected void doGet(HttpServletRequest request, HttpServletResponse response)
     throws ServletException, IOException {
   response.setContentType("text/html; charset=UTF-8");
   Tools.sendDisableCacheHeaders(response);
   final PrintWriter out = response.getWriter();
   out.println("<html>");
   out.println(" <body>");
   Cookie cookie = getCookie("carlos-cookie-test", request);
   if (cookie == null) {
     print(out, "No cookie set.");
   } else {
     print(out, "<b>Cookie ID</b>: " + cookie.getName() + "<br>");
     print(out, "<b>Value</b>: " + cookie.getValue() + "<br>");
     refreshCookie(cookie, response);
   }
   out.println("  <br>");
   out.println("  <form method=\"post\">");
   out.println("   <input type=\"submit\" value=\"create\" name=\"button\"><br><br>");
   out.println("   <input type=\"submit\" value=\"delete\" name=\"button\"><br><br>");
   out.println("   <input type=\"submit\" value=\"no-pass\" name=\"button\"><br>");
   out.println("  </form>");
   out.println(" </body>");
   out.println("</html>");
   out.close();
 }
コード例 #3
0
ファイル: index_jsp.java プロジェクト: h4ck3rm1k3/Infinit.e
 // getBrowserInfiniteCookie
 public static String getBrowserInfiniteCookie(HttpServletRequest request) {
   Cookie[] cookieJar = request.getCookies();
   if (cookieJar != null) {
     for (Cookie cookie : cookieJar) {
       if (cookie.getName().equals("infinitecookie")) {
         return cookie.getValue() + ";";
       }
     }
   }
   return null;
 } // TESTED
コード例 #4
0
ファイル: LoginAn.java プロジェクト: WaleedAshraf/UserProj
 public void doPost(HttpServletRequest req, HttpServletResponse res)
     throws IOException, ServletException {
   ArrayList<String> ar = new ArrayList<String>();
   boolean flag = false;
   Cookie[] cArr = req.getCookies();
   if (cArr != null) {
     for (int i = 0; i < cArr.length; i++) {
       Cookie c0 = cArr[i];
       if (c0.getName().equals("Name") && !c0.getValue().equals("Logout")) {
         res.sendRedirect("index.html");
         flag = true;
       }
     }
   }
   if (flag == false) res.sendRedirect("Login.html");
 }