This is a tip that detects whether the cookie settings for the user browser opens.
Tips are very simple. When the servlet receives a request, do not handle this request, but send a response, including a cookie in the response and require the browser to resend a request immediately after receiving this response, and Add this cookie in the request, and then detect this cookie in the request of the browser in the servlet, if not, this browser does not support cookies, there is a process of dealing with this request.
<%
IF (Request.getParameter ("Flag") == NULL) {
Cookie cookie = New cookie ("cookiefoo", on);
Response.addcookie (cookie);
String nextURL = Request.getRequestURL "? Flag = 1";
Out.println ("
}
Else {
Cookie [] cookies = Request.getCookies ();
Boolean cookiefound = false;
IF (cookies! = NULL) {
INT length = cookies.length;
For (INT i = 0; i Cookie cookie = cookies [i]; IF (cookie.getname (). Equal ("cookiefoo" && cookie.getValue (). Equal ("on")) { CookiefOnd = true; Break; } } } IF (cookiefound) { Out.println ("cookie is on"); } Else { Out.println ("Cookie IS OFF"); } } %>